Score:0

Why is the region content already rendered as markup?

us flag

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 }}
  </div>
{% 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.

4uk4 avatar
cn flag
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 https://drupal.stackexchange.com/questions/249856/custom-registration-twig-template
JonMcL avatar
us flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.