0

I want to append some custom text to taxonomy term pages using template_preprocess_taxonomy_term hook, But when I add my custom array key to it, the text don't show up on the term pages. PS I have cleared drupal cache many time.

Here is my code

function cars_theme_preprocess_taxonomy_term(&$variables) { if($variables['view_mode'] == 'full'){ $variables['content']['cars_view'] = "this is test"; } }

  • Your custom key? Did you render that in your template? For D8 {{ content.cars_view }} – Insasse Aug 25 '17 at 8:10
  • No, but if content is being rendered it should render all of the child variables. No? – Bharat Aug 25 '17 at 8:34
  • Ah now I get it. Under the content key you only can write render arrays , so you need to define your custom key like $variables['cars_view'] and render it {{ cars_view }}. – Insasse Aug 25 '17 at 9:06
  • Yes, you are right @insasse, I need to render it {{ cars_view }} but I had to add the output outside of content. – Bharat Sep 13 '17 at 4:45
1

Ok, so here is how I did it.

function cars_theme_preprocess_taxonomy_term(&$variables) {
      if($variables['view_mode'] == 'full'){
         $variables['cars_view'] = "this is test";
     }
}

And then in my twig file I output the cars_view as {{ cars_view }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.