This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

keystroke
keystroke

I would like to access whether or not maintenance mode is currently active in my default layout. Something like this....

{% if not site.maintenance %}
    {% component 'mySiteMenu' %}
{% endif %}
Flynsarmy
Flynsarmy

Put this in the code section of your layout:

function onStart() {
    $this['maintenance_mode'] = \Cms\Models\MaintenanceSetting::instance()->is_enabled;
}

Then in your page:

{% if maintenance_mode %}
    We're in maintenance, yo.
{% endif %}

Last updated

keystroke
keystroke

@Flynsarmy , thanks so much! 0_0)

keystroke
keystroke

Awesome, for reference, I have the following in my layout's code section....

function onStart() {
    $this['inMaintenance'] = \Cms\Models\MaintenanceSetting::instance()->is_enabled;
    $this['backendUser'] = BackendAuth::getUser();
}

And in my layout....

{% if backendUser or not inMaintenance %}
    {% component 'headerMenu' %}
{% endif %}

Thanks again!

Last updated

cto52010
cto52010

These examples will give errors, it should be MaintenanceSetting, without the "s".

Like: use Cms\Models\MaintenanceSetting; function onStart(){ $this['frontend_maintenance'] = MaintenanceSetting::instance()->is_enabled; }

See: https://octobercms.com/docs/api/cms/models/maintenancesetting

Last updated

Flynsarmy
Flynsarmy

Updated the posts, thanks!

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.