Symfony/Twig: “Node “1” does not exist for Node “Twig_Node”

I wanted to make 2 Versions of certain pages, some with a layout and some without (for an overlay). When I tried

{% if type == 'page' %}
  {% extends 'Core::layout.html.twig' %}
{% endif %}

it didn’t work and Symfony told me “Node “1” does not exist for Node “Twig_Node”. This seems to be a basic twig problem, an extend in an if doesn’t seem to be possible. What IS possible though is this:

{% extends type == 'page' ? 'Core::layout.html.twig' : 'Core::empty.html.twig' %}

creating an extra empty.html.twig is far better than creating two templates for each page.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.