I'm attempting to craft some custom layout HTML in one region of my theme (uswds_base, but this doesn't appear to be theme specific). The content of a typical region.html.twig file is like the following.

{% if content %}
  <div{{ attributes.addClass(classes) }}>
    {{ content }}
{% endif %}

Why is {{ content }} already rendered as a markup string in a region template? I'd like to be able to place individual blocks into different layout div's. I know I can use {{ elements.block_1 }}, but that seems inefficient since the blocks have already been rendered.

I can't figure out where the rendering is happening or if I'm just missing something obvious as to why {{ content }} isn't an array.

  • 4
    This is not a real template, it's only a theme wrapper. Normally theme wrappers provide the already rendered inner content in children, but in this case preprocessing moves it to content. For forms there is a similar problem, but there you can add an extra template for the inner parts. Don't know if there is an official way for regions, but it should be possible to make the adjustments one level up in the page template. And yes, don't try to render {{ elements.block_1 }}, see drupal.stackexchange.com/questions/249856/…
    – 4uk4
    Commented Jul 8, 2021 at 19:38
  • Yes! Stupid me failed to notice that page.primary_menu (the region I'm working on) is an array that contains the individual blocks and they are not yet rendered.
    – JonMcL
    Commented Jul 8, 2021 at 20:09


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.