Overriding blocks within included Twig templates

前端 未结 5 944
北荒
北荒 2020-12-12 21:19

Is there a generally \"good\" way to achieve this functionality? I have read about the \'use\' tag, which seems like the best option so far, but I still don\'t like that it

5条回答
  •  时光取名叫无心
    2020-12-12 21:47

    I got it to work with a very simple hack:

    Basically it behaves this way because without a {% extends "foo.html.twig" %} it doesn't understand the blocks and simply renders them in place.

    So let's extend... nothing:

    {% extends "nothing.html.twig" %}
    

    This nothing is really just 1 block:

    # nothing.html.twig
    {% block main %}
    {% endblock %}
    

    The only thing is that you need to wrap everything in a block, this fake "main" block.

提交回复
热议问题