Thursday 15 January 2015

php - Symfony2 - Twig - How can I send parameters to the parent template? -


I am working on a PHP project using Symfony2 with tweg template, and I can not find a solution to this problem Could. / P>

I have an administrator bundle and all templates are from admin base, which has a master template with menu.

I have to set the current tab of the menu in the base template, the page is selected when selected on that page.

The basis here What is a way to pass the parameter to the template? A simple example is:

base.html.twig :

  {# base.html.twig #} ... & lt; Ul & gt; & Lt; Li {% if selected from the menu. Default ('one') == 'one'%} class = "selected" {% endif%}> a & lt; / Li & gt; & Lt; Li {% if selected from menu == 'two'%} class = "selected" {% endif%} & gt; Two & lt; / Li & gt; & Lt; Li {% if selected from menu == 'three'%} class = "selected" {% endif%} & gt; Three & lt; / Li & gt; & Lt; / Ul & gt; ...   

page2.html.twig :

  {# page2.html.twig #} {% extends' Output page from yourBundle :: base.html.twig '%} {% set menu_cicad =' two '%}   

rendering Page 2.html.twig:

 < Code> & lt; Ul & gt; & Lt; Li & gt; A & lt; / Li & gt; & Lt; Li class = "selected" & gt; Two & lt; / Li & gt; & Lt; Li & gt; Three & lt; / Li & gt; & Lt; / Ul & gt;    

No comments:

Post a Comment