74

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?

Chris
  • 8,031
  • 10
  • 41
  • 67

1 Answers1

174

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

{{ block('blockName') }}
Darryl Hein
  • 142,451
  • 95
  • 218
  • 261
greg0ire
  • 22,714
  • 16
  • 72
  • 101
  • Thanks - I currently used the notation of having a default value, which is then overwritten in child templates. Thx! – Chris Mar 08 '12 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 '21 at 16:35