template_preprocess_taxonomy_term(&$variables)
Prepares variables for taxonomy term templates.
Default template: taxonomy-term.html.twig.
Parameters
array $variables: An associative array containing:
-
elements: An associative array containing the taxonomy term and any fields attached to the term. Properties used:
- #taxonomy_term: A \Drupal\taxonomy\TermInterface object.
- #view_mode: The current view mode for this taxonomy term, e.g. 'full' or 'teaser'.
- attributes: HTML attributes for the containing element.
File
- core/modules/taxonomy/taxonomy.module, line 251
- Enables the organization of content into categories.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | function template_preprocess_taxonomy_term(& $variables ) { $variables [ 'view_mode' ] = $variables [ 'elements' ][ '#view_mode' ]; $variables [ 'term' ] = $variables [ 'elements' ][ '#taxonomy_term' ]; /** @var \Drupal\taxonomy\TermInterface $term */ $term = $variables [ 'term' ]; $variables [ 'url' ] = $term ->url(); // We use name here because that is what appears in the UI. $variables [ 'name' ] = $variables [ 'elements' ][ 'name' ]; unset( $variables [ 'elements' ][ 'name' ]); $variables [ 'page' ] = $variables [ 'view_mode' ] == 'full' && taxonomy_term_is_page( $term ); // Helpful $content variable for templates. $variables [ 'content' ] = array (); foreach (Element::children( $variables [ 'elements' ]) as $key ) { $variables [ 'content' ][ $key ] = $variables [ 'elements' ][ $key ]; } } |
Please login to continue.