By tim.plunkett on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.4.x
Issue links:
Description:
All layout templates now have a variable called region_attributes available.
Similar to the existing variable content, this is an array keyed by region name.
Inside are the attributes for that HTML tag.
Before
// In mylayout.html.twig
<div{{ attributes }}>
<div class="region-first">
{{ content.first }}
</div>
<div class="region-second">
{{ content.second }}
</div>
</div>
After, Option 1
// In .theme
function template_preprocess_mylayout(&$variables) {
$variables['region_attributes']['first']['class'][] = 'region-first';
$variables['region_attributes']['second']['class'][] = 'region-second';
}
// In mylayout.html.twig
<div{{ attributes }}>
<div {{ region_attributes.first }}>
{{ content.first }}
</div>
<div {{ region_attributes.second }}>
{{ content.second }}
</div>
</div>
After, Option 2
// In mylayout.html.twig
<div{{ attributes }}>
<div {{ region_attributes.first.addClass('region-first') }}>
{{ content.first }}
</div>
<div {{ region_attributes.second.addClass('region-second') }}>
{{ content.second }}
</div>
</div>
Impacts:
Module developers
Themers