Hello,

I created a field of taxonomy in drupal 7 (field_tax). With Contemplate module, I retrieve the data from the field with the syntax: <? php print $ node-> field_tax ['fr '] [0] ['taxonomy_term'] -> name?>.

But I have an error in my template:
* Notice: Undefined index: in taxonomy_term include () (line 28 of / var / ... / node.tpl.php).
* Notice: Trying to get property of non-object in include () (line 28 of / var / ... / node.tpl.php ).

What should I do?

Thank you.

Comments

Cameron Little’s picture

I'm looking for the same answer. I've tried a bunch of different things but can't get past the [taxonomy_term] => stdClass Object (

Edit: found this - sorta clears things up... sorta - http://robotlikehuman.com/web/how-print-taxonomy-term-nodetplphp-drupal-7

NickWebman’s picture

lol. Sorry Cameron - I wrote that article out of frustration while trying to find a solution to this problem. If you guys find a more comprehensive solution please let me know so I can update the article.

-Nick

ransom’s picture

Devl helps you understand things better get the upstream/downstream things and how they relate. Though judging by your blog you use it no? http://drupal.org/project/devel

could probably use http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module/func... or http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module/func... and get them as objects more directly.

jrdixey’s picture

print $node->field_myfield['und'][0]['taxonomy_term']->name;

This worked for me. I tried using ['#terms'] instead of ['und'] as recommended here http://drupal.org/node/1032978 but that didn't work, although it didn't generate an error.

Hope this helps someone out there.

jrdixey’s picture

This produces the same result:

print $field_myfield[0]['taxonomy_term']->name;