I have what is probably a common question ... How do render arrays get parsed into the the twig template - If we have a controller class which outputs a render array, such as:
$output['element1']=array ("#type"=>"markup","#markup"=>"Hello World!");
$output['element2']=array ("#type"=>"markup","#markup"=>"Today is a nice day!");
Now, lets say that we're using the bootstrap framework, hence using row and columns for layout, if we want the array elements to be output in the following manner:
<div class="row">
<div class="col-md-12">
Hello World!
</div>
</div>
<div class="row">
<div class="col-md-12">
Today is a nice day!
</div>
</div>
How can this be done? It is clear that Drupal will initially use the page.html.twig template, which will call the region.html.twig template, which in turn will call the block.html.twig template in order to display the render array. But, the block.html.twig will output the render array as:
Hello World! Today is a nice day!
Namely,it will not output the div tags - mostly because the block.html.twig doesn't know about them. And looking at the block.html.twig it appears that the output is only available as 'content':
{{ content}}
And there is no way of templating the content in the following way:
<div class="row">
<div class="col-md-12">
{{ content['element1'] }}
</div>
</div>
<div class="row">
<div class="col-md-12">
{{ content['element2'] }}
</div>
</div>
Secondary related query:
What would also be useful, is being able to ascertain which class called the page.html.twig so that one could use the {% if calling_page="page name" %} in the block.html.twig template
Hopefully, you get what I am outining here. Thanks in advance and please operate upon the premise I'm totally new to Drupal when outlining solutions.