In Drupal 8 I need a way to get the Current pages title or Taxonomy name/ID.

In the template taxonomy-term.html.twig the variable works:

{{ term.id }}

I need the variable to work in page.html.twig

the following variables work only if the current page type is a node and not a taxonomy:

{{ head_title_array.title }} and {{node.field.category.entity.tid.value}}

I need to access this variable in the page template in order to use it as a class for a region based on what taxonomy page type is being displayed.


prints out page__taxonomy__term__# or null if not a taxonomy page:

{{ theme_hook_suggestions }}

prints out the title of the current page regardless of type:

{{ page['#title'] }}
  • See this drupal.stackexchange.com/questions/192232/… how to get the term id in preprocess
    – 4uk4
    May 25, 2016 at 18:12
  • thanks but i'm not sure where this goes. i installed Devel and i have been using knit to try and make twig variables more readable.however if i use a view to display taxonomy type pages than some variables do not work
    – blu
    May 25, 2016 at 19:26


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.