I've created a base twig template which contains some basic "maintenance mode" logic. This works perfectly as long as the main ENVIRONMENT
in the .env file is set as dev
, but fails for staging or production.
{% if site.maintenanceMode is defined and site.maintenanceMode %}
{% if site.maintenanceIpAddress is defined %}
{% set currentIpAddress = craft.app.request.userIP %}
{% if currentIpAddress != site.maintenanceIpAddress %}
{% include('/maintenance') %}
{% exit %}
{% endif %}
{% else %}
{% include('/maintenance') %}
{% exit %}
{% endif %}
{% endif %}
<!DOCTYPE html>
<html lang="en"…
Being fairly new to CraftCMS, I'm somewhat at a loss as to why this might be occurring and there's nothing in either the …/storage/logs/web.log
file or the main nginx error log file. (In short no errors appear to be being thrown.)
I've tried flushing all of the available caches (including the template cache, etc.) and rebuilding the config, etc. to no avail.
include
Twig function (which returns the given rendered template but need to be output using{{ include('maintenance.twig') }}
) and theinclude
Twig tag (which directly outputs the rendered template:{% include 'maintenance.twig' %}
).