1

Do you know if it's possible to print a taxonomy term field inside a views-view.tpl.php template in Drupal 7?

For example, you would do this:

<?php print render($content['field_example_field']); ?>

in node--content-type.tpl.php.

What would be the equivalent to get a specific taxonomy term field in views-view--name-of-view.tpl.php?

Thanks in advance!

4 Answers 4

2

For this you need to create the Row style output template file for the view.

For ex: views-view-fields--your_view_name--block.tpl.php.

In this file you get the row array and then you can print your field like:

$row->field_example_field[0]['raw']['value']
1

For this you need to do the following;

First: ( on node page )

print_r($row);
exit;

You can see the list.

Now your can print this as;

$row->field_example_field[0]['raw']['value']

And you get the value.

1

In your views template file just add this line of code;

print render($fields['term_node_tid']->content);
1

Thanks guys for your responses, but I figured it out. The view I was targeting was a content view not a term view, didn't think it was possible to add a Taxonomy term field. So I thought I could add the term field in a template (hence the question I asked here) but I worked it out in Views instead:

Went to Relationship, added "Content: Taxonomy terms on node". Selected the Vocabularies I wanted to add in relationship. Then went to Fields, "Add" and selected "Taxonomy term: Example Field".

Sorry if I wasn't clear enough, hope this helps someone else (spent many countless hours googling this).

Your Answer

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

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