Le 23/06/2011 03:18, Kevin a écrit :
Hey all,
I'm integrating the FOS UserBundle (many thanks to the bundle developers, btw) into an application, and I'm trying to find the cleanest way to integrate the bundle templates stylistically.

We have a base template that looks something like:

{# MyBundle::base.html.twig #}
...
{% block body %}
...
<div id='content'>
    {% block content %}
    {% endblock %}
</div>
{% endblock %}
...

For most of the user bundle templates, the default content is fine for our purposes, so my first thought would just be to override FOSUserBundle::layout.html.twig (which all the user bundle templates extend from) with something extending our base template. However, I'd like the final result to look something like:

{# Overrides FOSUserBundle::layout.html.twig #}
{% extends 'MyBundle::base.html.twig %}
{% block content %}
<div class='user-info-container'>
    {# 'content' block from user bundle templates goes here! #}
</div>
{% endblock %}

So the issue is that our base template already has a 'content' block that's serving a different purpose than the 'content' block in the user bundle templates.

Naturally we could override all the lower-level user bundle templates we're using, and just modify their 'content' blocks directly. We could also rename the 'content' block of our base template and update our other templates which inherit from it. Neither of these options would be terribly difficult, but I'm wondering if there's a cleaner way to do it. I'm almost imagining something like:

{# Overrides FOSUserBundle::layout.html.twig #}
{% extends 'MyBundle::base.html.twig with { 'content': 'base_content' } %}
{% block base_content %}
<div class='user-info-container'>
    {% block content %}
    {% endblock %}
</div>
{% endblock %}

Anyone know if something like this is feasible, or if there's a better way to be handling this situation?

Thanks!
Kevin

You can also overwrite the bundle's template called by the controller. If you look at the bundle, we use 2 templates each time: one responsible of the actual rendering of the content (the name is suffixed by /_content/) and another one called by the controller and doing the inheritance to the layout, which calls the first one. This allows you to replace it if the name /content/ does not fit in your own layout.

--
Christophe | Stof

--
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to