Skip to content

Commit

Permalink
Merge pull request #192 from isubit/D8ISUTHEME-180
Browse files Browse the repository at this point in the history
D8ISUTHEME-180 Add front and views classes to body
  • Loading branch information
sacarney committed Apr 21, 2022
2 parents 7fdfb79 + 871fb1a commit 3c62a77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion iastate_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Implements template_preprocess_html().
*
* Add node-id_{id} class.
*/
function iastate_theme_preprocess_html(&$variables) {

/* Add node-id_ and node-type_ classes to body */
$node = \Drupal::request()->attributes->get('node');
if ($node instanceof NodeInterface) {
$variables['attributes']['class'][] = 'node-id_' . $node->id();
}
if (isset($variables['node_type'])) {
$variables['attributes']['class'][] = 'node-type_' . $variables['node_type'];
}

/* Add views classes to body */
$route = \Drupal::routeMatch()->getRouteObject();
$view_id = $route->getDefault('view_id');
$display_id = $route->getDefault('display_id');

if ($view_id) {
$variables['attributes']['class'][] = 'view_' . $view_id;
$variables['attributes']['class'][] = 'view-display_' . $display_id;
}
}

/*
Expand Down
1 change: 1 addition & 0 deletions templates/layout/html.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
is_node_edit == 'edit' ? 'node-form node-form_' ~ 'edit',
is_node_add == 'add' ? 'node-form node-form_' ~ 'add',
is_node_delete == 'delete' ? 'node-form node-form_' ~ 'delete',
is_front ? 'is_front' : 'not_front',
]
%}
<body{{ attributes.addClass(body_classes) }}>
Expand Down

0 comments on commit 3c62a77

Please sign in to comment.