Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[RFC] Convention to load template without override #17054

Copy link
Copy link
Closed
@xavierleune

Description

@xavierleune
Issue body actions

Hi,

Actually in symfony, when you want to override a template from a bundle, you have to override this template into your app/Resources/OverridenBundle. But you actually have to copy/paste this template.
If you try to extend it, you will fall into an infinite loop, as the loader will try to load the overriden template, which try to load the overriden template, etc.

Of course if your bundle has some "extension point" (in fact, like sonata, you can have in your bundle a template "myfeature_full.html.twig" and a template "myfeature.html.twig" which just extends the full template, allowing overriden templates to uses blocks and so) you can use it. But it needs more template and the bundle you want to override must allow this.

Actually there is no technical way to bypass this behaviour and a little convention can do the trick.

Let's imagine the convention is to add the "!" mark at the beginning of the name of the template when you want to extends it, you'll be able to do that kind of thing:

src/vendor/ccmbenchmark/mybundle/src/Resources/views/base.html.twig

    {% block title %}<h1>Hello</h1>{% endblock %}
    {% block content %}
         {# big content with some logic i don't want to copy/paste #}
     {% endblock %}

app/Resources/MyBundle/views/base.html.twig

    {% extends '!MyBundle::base.html.twig' %}
    {% block title %}<h2>Hi !</h2>{% endblock %}

The "!" basically say's "Hey, let's drop off all override. I just want this template from this bundle".

What do you think about this feature? Actually that would be very useful in a lot of cases and will just help to empower bundles !

If this was accepted, I would agree to dev this feature.

/cc @dunglas

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.