I use the Symfony2 framework combined with the FOSUserBundle. I modified the layout by overwriting some FOSUserBundle templates. This is working very well! The only problem is that I cannot set variables in my templates that extend templates from the FOSUserBundle that are overwritten by my own templates. Difficult to describe, but I try it:
I am overriding the Registration/register_content.html.twig like this:
{% trans_default_domain 'FOSUserBundle' %}
{% set section='register' %}
<h1>{{ 'Anmeldung'|trans }}</h1>
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST">
{{ form_widget(form) }}
<div>
<input type="submit" value="{{ 'registration.submit'|trans }}" />
</div>
</form>
(/home/simon/server/html/portal/app/Resources/FOSUserBundle/views/Registration/register_content.html.twig)
The point is that I want to set the section variable for my bundle's layout.html.twig to highlight the current section in the menu. This works fine with my regular templates (that are not overwritten from FOSUserBundle)
I also have overwritten layout.html.twig from FOSUserBundle:
{% extends 'MyBundle::layout.html.twig' %}
{% block content %}
{% block fos_user_content %}{% endblock %}
{% endblock %}
(/home/simon/server/html/portal/app/Resources/FOSUserBundle/views/layout.html.twig)
If I set my variable direclty in that layout file it works. But that's not what I want.
How can I solve the problem?
ADDITIONAL INFORMATION:
My menu looks like this
<ul class="nav nav-pills menu">
{% if section is not defined %}
{% set section = '__dummy_undefined' %}
{% endif %}
<li{% if section == 'home' %} class="active"{% endif %}><a href="{{ path('home') }}"> {{ 'general.home'|trans }}</a></li>
<li{% if section == 'search' %} class="active"{% endif %}><a href="{{ path('search') }}">{{ 'general.search'|trans }}</a></li>
<li{% if section == 'events' %} class="active"{% endif %}><a href="{{ path('events') }}">{{ 'general.calendar'|trans }}</a></li>
<li{% if section == 'register' %} class="active"{% endif %}><a href="{{ path('fos_user_registration_register') }}">{{ 'general.register'|trans }}</a></li>
</ul>
So the variable is defined right before it is used. The menu is contained in a menu.html.twig file which is included like that:
{% include 'DancePortalFrontendBundle::headline.html.twig' %}
The include comes BEFORE {% block content %} This should never be displayed! {% endblock %}
But even if i do the include after or in the content block, I do not get the section value that I set in the register_content.html.twig
Does somebody know how to solve that?