1

I want to modify the output of a 'Reference on Taxonomy Field'. I created a 'Reference on Taxonomy Field' in a content type that relates to terms in a vocabulary that have a title and a picture. The content type is displayed by a view that outputs the fields of the content type. I added the field and created the template file views-view-field--kategorieseiten--page--field-produkteigenschaften.tpl.php and it works.

It should be displayed like this:

<a rel="tooltip" data-placement="bottom" target="_blank" data-original-title="TERM_TITLE">OUTPUT_OF_THE_TERM_PICTURE</a>

The problem is that I don't know how to address the fields from the taxonomy term, since they are not directly stored in the node.

Thanks for your help!

0

I managed to load the fields of the taxonomy term with this code:

<?php

/**
 * @file
 * This template is used to print a single field in a view.
 *
 * It is not actually used in default Views, as this is registered as a theme
 * function which has better performance. For single overrides, the template is
 * perfectly okay.
 *
 * Variables available:
 * - $view: The view object
 * - $field: The field handler object that can process the input
 * - $row: The raw SQL result that can be used
 * - $output: The processed output that will normally be used.
 *
 * When fetching output from the $row, this construct should be used:
 * $data = $row->{$field->field_alias}
 *
 * The above will guarantee that you'll always get the correct data,
 * regardless of any changes in the aliasing that might happen if
 * the view is modified.
 */
?>

<?php $taxonomy_term = taxonomy_term_load(54); ?>
<a rel="tooltip" data-placement="bottom" target="_blank" data-original-title="<?php print $taxonomy_term->name; ?>"><img src="<?php print $taxonomy_term->field_icon['und'][0]['filename']; ?>"></a>


But I want to load the terms dynamically from the tid stored in this field:

enter image description here

The field 'field_produkteigenschaften' is part of the content type and is stored in the node object.

How do I now address the tid stored in the field 'field_produkteigenschaften' in this template?

0

I could get the output with:

$row->_field_data['nid']['entity']->field_produkteigenschaften['und'][0]['tid']

Complete code:

<?php if ($row->_field_data['nid']['entity']->field_produkteigenschaften) { ?>
<?php foreach ($row->_field_data['nid']['entity']->field_produkteigenschaften['und'] as &$eigenschaft) { ?>
<?php $taxonomy_term = taxonomy_term_load($eigenschaft['tid']); ?>
<a rel="tooltip" data-placement="bottom" target="_blank" data-original-title="<?php print $taxonomy_term->name; ?>"><img src="<?php print image_style_url("icon", $taxonomy_term->field_icon['und'][0]['uri']); ?>"></a>&nbsp;
<?php } ?>
<?php } else { print "&nbsp;"; } ?>

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.