Make default region classes in layout templates optional

Created on 10 September 2017, over 7 years ago
Updated 26 December 2023, about 1 year ago

Problem/Motivation

DS provides layouts and accompanying CSS that may optionally be enabled for a given view mode.

In some cases, those using different CSS may also wish to use different classes. For example, a theme integrating a CSS framework like Bulma or Bootstrap might use classes appropriate to those frameworks.

Currently this can be done at the template level. For example, here's a sample template to add appropriate Bulma-specific classes in a child template:

{% extends "@ds/ds-2col.html.twig" %}
{% set attributes = attributes.addClass('columns') %}
{% set left_attributes = left_attributes.addClass('column') %}
{% set right_attributes = right_attributes.addClass('column') %}

However, the (unneeded) DS classes will also be added, since they're added unconditionally in the DS template.

Proposed resolution

Use a flag variable, default_region_classes, that determines whether default classes are added to regions.

This is parallel to the default_row_class variable passed in core to views style templates. See the stable theme's views-view-unformatted.html.twig template.

Current code snippet in ds-2col.html.twig:
<{{ outer_wrapper }}{{ attributes.addClass('ds-2col', 'clearfix') }}>

Proposed revised code snippet:

{%
  set classes =  default_region_classes ? [
    'ds-2col',
    'clearfix',
  ] : []
%}
<{{ outer_wrapper }}{{ attributes.addClass(classes) }}>

How a child template would work with this:

{% extends "@ds/ds-2col.html.twig" %}
{% set attributes = attributes.addClass('columns') %}
{% set left_attributes = left_attributes.addClass('column') %}
{% set right_attributes = right_attributes.addClass('column') %}
{% set default_region_classes = false %}

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Closed: won't fix

Version

3.0

Component

Code

Created by

🇨🇦Canada nedjo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024