0

Does anyone know how to render a dynamically generated block name using the Sonata Block Bundle? An example of what I am trying to achieve is:

page.html.twig:

<div class="content">
 {{ sonata_block_render({
'name': '/content/blocks/{{ suffix }}'
}) }}
</div>

where suffix is a variable passed to the twig template, e.g. about-us. This allows me to use a single template for rendering all my CMS content. I have tried doing the above, but that doesn't seem to work.

newbie
  • 408
  • 1
  • 4
  • 14

1 Answers1

3

You're already in twig context, that's why {{ }} didn't work. You'll need the string concatenation operator (~) like this:

<div class="content">
{{ sonata_block_render({
    'name': '/content/blocks/' ~ suffix
}) }}
</div>
Maerlyn
  • 33,687
  • 18
  • 94
  • 85
  • Thanks for the response. I did eventually work this out and should have updated my question. I'll accept your answer as its exactly what I did! – newbie Aug 04 '13 at 16:13