0

I am trying to add to my node pages a taxonomy listing that includes fields I've added to the taxonomy. I'm able to add the field from the corresponding note into my page--node.tpl.php file with the following code:

<?php $field_country = field_view_field('node', $node, 'field_country'); 
     print render($field_country);
?>

Unfortunately this does not output the corresponding field I've attached to the taxonomy, which is an image field that contains a flag for the country.

Is there a way to print this field into page--node.tpl.php using Drupal 7 and no additional modules? It would be very useful to use these fields attached to taxonomy for more than just the taxonomy pages.

Thanks for the help!

1

This can be done without any need to use php code and tpl.php files. The capability to generate content based upon a taxonomy including images can be done by using the modules. These modules are intended to define and implement a site's design and are well written and tested. Template files will handle the layout and appearance of your content, but are not necessary for the content you have described. IF you are not familiar with Drupal, take a little time to learn more about what it can do before you make changes in the template files. If you are familiar with Drupal, then it might be helpful to understand more regarding what you are trying to do.

  • Thanks for the tip, I'll try writing a module instead. I have more experience calling fields into TPL files via Contemplate in Drupal 6, but I'm a big fan of Render API in Drupal 7 which lets me render the fields when and where I want. I didn't know it was poor form to do what I was doing, it certainly worked just fine — with the exception of not rendering the taxonomy's field. – Nick McClellan Nov 5 '11 at 15:02
  • I would recommend that you write yourself a taxonomy term formatter that plots the image and country name. You'll then be able to insert that field with assigned formatter with clean hands. – Artur May 5 '12 at 11:41

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.