Symfony/Twig: "Node "1" does not exist for Node "Twig_Node"

June 25, 2014 at 06:18

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.

Tags: extends Twig

Hinterlasse einen Kommentar: