Twig extend template on condition

前端 未结 5 1025
刺人心
刺人心 2020-12-14 00:23

I use Symfony 2 with Twig and my question is pretty straightforward:

In a view I want to extend one of the layouts based on a variable. If the variable is fals

5条回答
  •  盖世英雄少女心
    2020-12-14 00:29

    Try this one:

    {% extends intro == 'false' 
        ? 'UdoWebsiteBundle::layout.html.twig' 
        : 'UdoWebsiteBundle::layout_true.html.twig' %}
    

    Idea taken from here: http://jorisdewit.ca/2011/08/27/extending-different-layouts-for-ajax-requests-in-twig-symfony2/

提交回复
热议问题