For theming purpose, I would like to add in body class the vocabulary name (or ID) of the current taxonomy. I know how to add a class based on taxonomy term ID. Here is a taxonomy example :
Color (vocabulary) – red (term id = 1) – green (term id = 2) – yellow (term id = 3)
Actaully,
I know how to get :
<body class="term-id-1">
I would like to have :
<body class="vocabulary-id-1">
or
<body class="vocabulary-name-color">
I’ve tried :
function mytheme_preprocess_html(&$ variables) { // Works if (\Drupal::routeMatch()->getRouteName() == 'entity.taxonomy_term.canonical') { $ variables['term_id'] = \Drupal::routeMatch()->getRawParameter('taxonomy_term'); } // doesn't work if (\Drupal::routeMatch()->getRouteName() == 'entity.taxonomy_vocabulary.canonical') { $ variables['vocabulary_id'] = \Drupal::routeMatch()->getRawParameter('taxonomy_vocabulary'); } }