Problem/Motivation

Add route to body as class name

Proposed resolution

add to THEME_preprocess_html(&$variables) in *.theme file:

$route_name = \Drupal::routeMatch()->getRouteName();
$route_class = Html::cleanCssIdentifier(str_replace('.', '-', $route_name));
$variables['attributes']['class'][] = 'page-route-' . $route_class;

Issue fork bootstrap5-3570047

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jannakha created an issue. See original summary.

jannakha’s picture

Status: Active » Needs review

CSS classes added to <body>:

  • page-route-entity-node-canonical
  • page-route-entity-node-form-edit
  • page-route-entity-taxonomy-vocabulary-edit-form
  • page-route-view-search-node

can be used in custom styling like:

body[class^="page-route-view"] {
// special treatment for views
}
vladimiraus’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for your contributions. Applies and works.

vladimiraus’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for contribution. Committed.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • vladimiraus committed ec14710a on 4.0.x
    feat: #3570047 Add route to body as class name
    
    By: jannakha
    By:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.