71

How can I render a block multiple times within a view in a twig template? Currently I do have a block, let's call it something defined in an included (via render) twig file. I then include it at the layout-twig file using the following:

{% block something %}{% endblock %}

Everything is fine, however as soon as I call this tag a second time, I get the following error message:

The block 'something ' has already been defined in "::layout.html.twig" 

Therefore: How can I render a block multiple times?

1 Answer 1

170

The notation you're showing us is for defining and rendering a block. Rendering only is done this way:

{{ block('blockName') }}
2
  • Thanks - I currently used the notation of having a default value, which is then overwritten in child templates. Thx!
    – Chris
    Mar 8, 2012 at 14:06
  • This syntax is not applicable to .tera templates in Rust. no criticism, but it might interest people searching for the same thing as me right now
    – pfincent
    Sep 11, 2021 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.