-1

I need to display Taxonomy term image field on the node display page instead of the term name.

Other fields are being printed like below and the $content variable is not printed any where. Any suggestions?

$policies = $node->field_policies['und'][0]['safe_value'];
0

In your hook_preprocess_node load your taxonomy term and get the field image value

function hook_preprocess_node(&$variables) {   
   $term = $variables['elements']['#node']->get('your_field_taxonomy_term')->getValue();
   if (!empty($term)) {
    $terme = Term::load($term[0]['target_id']);
    $image = $terme->get('your_field_image')->getValue();
    $variables['image'] = $image; 
  }
 }

in yout twig file print the image variable.

hope this will help.

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.