Add block utility classes as a template config

Created on 20 September 2023, over 1 year ago
Updated 1 November 2023, over 1 year ago

Problem/Motivation

The current implementation of block.html.twig does not allow additional classes from embedding templates.

Proposed resolution

Change the classes array to accept a template config.

{#
/**
 * ...
 * Available config:
 * - block_utility_classes: An array of utility classes for block.
 */
#}
{% set block_classes = [
  'block',
  'block-' ~ configuration.provider|clean_class,
  'block-' ~ plugin_id|clean_class,
  bundle ? 'block--type-' ~ bundle|clean_class,
  view_mode ? 'block--view-mode-' ~ view_mode|clean_class,
]|merge(block_utility_classes ? block_utility_classes : []) %}

With this, a sub-theme template could expand upon the classes added to the block div.

{% include '@uswds_base/block/block.html.twig' with {
  block_utility_classes: [
    'my-custom-class',
  ],
} %}

Remaining tasks

The following example is taken from Radix. This same concept could be applied to other template files.

- [ ] Identify other template enhancement opportunities.

✨ Feature request
Status

Closed: works as designed

Version

3.4

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jcandan

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

Comments & Activities

Production build 0.71.5 2024