1

I have a content type "Produkte" with the field "field_produktmerkmale" which is a term reference field addressing the taxonomy vocabulary "Produktmerkmale". The terms have a title, a description and an image field.

When I display "field_produktmerkmale" it shows only the title with a link to the taxonomy, but I want to display the images instead of the title. So I created the "field--field_produktmerkmale--produkte.tpl.php" to modify the output.

But how do I know address the image from this template?


var_dump($items) gives me the following result: (Just an excerpt of the first element)

[1]=> array(4) { ["#type"]=> string(4) "link" ["#title"]=> string(15) "Batteriebetrieb" ["#href"]=> string(16) "taxonomy/term/89" ["#options"]=> array(3) { ["entity_type"]=> string(13) "taxonomy_term" ["entity"]=> object(stdClass)#154 (11) { ["tid"]=> string(2) "89" ["vid"]=> string(1) "9" ["name"]=> string(15) "Batteriebetrieb" ["description"]=> string(68) "Batteriebetrieb: Mit automatischer Abschaltung zur Batterieschonung" ["format"]=> string(8) "php_code" ["weight"]=> string(1) "0" ["language"]=> string(3) "und" ["i18n_tsid"]=> string(1) "0" ["vocabulary_machine_name"]=> string(15) "produktmerkmale" ["field_icon2"]=> array(1) { ["und"]=> array(1) { [0]=> array(15) { ["fid"]=> string(3) "805" ["uid"]=> string(1) "1" ["filename"]=> string(6) "CE.gif" ["uri"]=> string(21) "public://icons/CE.gif" ["filemime"]=> string(9) "image/gif" ["filesize"]=> string(3) "525" ["status"]=> string(1) "1" ["timestamp"]=> string(10) "1394787947" ["type"]=> string(5) "image" ["rdf_mapping"]=> array(0) { } ["image_dimensions"]=> array(2) { ["width"]=> string(2) "50" ["height"]=> string(2) "50" } ["alt"]=> string(0) "" ["title"]=> string(0) "" ["width"]=> string(2) "50" ["height"]=> string(2) "50" } } } ["rdf_mapping"]=> array(5) { ["rdftype"]=> array(1) { [0]=> string(12) "skos:Concept" } ["name"]=> array(1) { ["predicates"]=> array(2) { [0]=> string(10) "rdfs:label" [1]=> string(14) "skos:prefLabel" } } ["description"]=> array(1) { ["predicates"]=> array(1) { [0]=> string(15) "skos:definition" } } ["vid"]=> array(2) { ["predicates"]=> array(1) { [0]=> string(13) "skos:inScheme" } ["type"]=> string(3) "rel" } ["parent"]=> array(2) { ["predicates"]=> array(1) { [0]=> string(12) "skos:broader" } ["type"]=> string(3) "rel" } } } ["attributes"]=> array(2) { ["typeof"]=> array(1) { [0]=> string(12) "skos:Concept" } ["property"]=> array(2) { [0]=> string(10) "rdfs:label" [1]=> string(14) "skos:prefLabel" } } } } 

The data I need would be in field_icon2 with the filename and in description (as a tooltip). But how do I address ut correctly?

I tried:

<?php print $item['#options']['entity']['description']; ?> 

But I get and error:

Notice: Trying to get property of non-object in include() 
2
  • See: Rendering Drupal 7 Fields the Right Way. Commented Mar 14, 2014 at 13:25
  • I tried using it, but it gives me an error: Notice: Undefined variable: nid in include() Commented Mar 14, 2014 at 13:31

1 Answer 1

0

$item['#options']['entity'] is an object, so you should be accessing "description" this way:

$item['#options']['entity']->description

But as Adam stated, you should render it the right way with field_view_field method. The error you mentioned it's just a problem with sending the right parameters to the method.

1
  • So should I render it in the node--produkte.tpl.php or in the field--field_produktmerkmale--produkte.tpl.php? But why is it the wrong parameter? Which parameter should I use? the tutorial said to send the $nid as a parameter, but since I am in a field.tpl I guess there is no access to the $nid?! Sorry, but I am new to drupal. Commented Mar 14, 2014 at 14:12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.