Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291641

Add current user language and node ID classes to body

$
0
0

I'm used to have a current user language and a node ID classes on body.
I'v found this solution, is there a better way?
Thank's

>> On my customtheme.theme file:

 function customtheme_preprocess_html(&$variables) {
   if ($node = \Drupal::request()->attributes->get('node')) {
     $variables['attributes']['class'][] = 'page-node-' . $node->id();
   }
   $variables['attributes']['class'][] = \Drupal::languageManager()->getCurrentLanguage()->getId();
 }

>> On html.html.twig

{%
set body_classes = [
  logged_in ? 'user-logged-in',
  not root_path ? 'path-frontpage' : 'path-' ~ root_path|clean_class,
  path_info.args ? 'path-' ~ path_info.args,
  node_type ? 'page-node-type-' ~ node_type|clean_class,
  db_offline ? 'db-offline',
]
%}

Thank's for all


Viewing all articles
Browse latest Browse all 291641

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>