I am using the statement include for dynamic sections in MODx.
1 2 3 4 5 6 7 8 9 10 |
{% for page in pages.children.visible %} {% set color = page.header.color %} {% set classes = page.header.body_classes %} <section id="{{ classes }}" class="{{ color }}"> {% include 'layouts/' ~ classes ~ '.html.twig' %} </section> {% endfor %} |
It was working fine so far, but today I received the following exception that basically means, my snippet tried to include a file that doesn’t exist. The variableĀ classes was empty that causesĀ a broken website.
1 |
RuntimeException (400) Template "layouts/.html.twig" is not defined in "default.html.twig" at line 12. |
In my case I improved my snippet with an if condition.
1 2 3 4 5 6 7 |
{% if classes is not empty %} <section id="{{ classes }}" class="{{ color }}"> {% include 'layouts/' ~ classes ~ '.html.twig' %} </section> {% endif %} |