I'm trying to figure out how to access parts of the $content array in my template files, but I'm not having any luck.
First I did this:
hide($content['field_review_nationality']);
I want to only output the country name (taxonomy term) without any other code, but this is what happens:
This:
print render($content['field_review_nationality']);
outputs:
<div class="field field-name-field-review-nationality field-type-taxonomy-term-reference field-label-inline clearfix"><div class="field-label">Nationality: </div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/75" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Switzerland</a></div></div></div>
This:
print render($content['field_review_nationality'][0]);
outputs:
<span thmr="thmr_64"><a href="/taxonomy/term/75" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Switzerland</a></span>
Things like this output nothing:
render($content['field_review_nationality'][0]['taxonomy_term']['tid']);
This is the relevant section from print_r($content); -- I want to only print "Switzerland" without any other code or links:
[field_review_nationality] => Array
(
[und] => Array
(
[0] => Array
(
[tid] => 75
[taxonomy_term] => stdClass Object
(
[tid] => 75
[vid] => 11
[name] => Switzerland
[description] =>
[format] =>
[weight] => 0
[vocabulary_machine_name] => countries23239
[rdf_mapping] => Array
(
[rdftype] => Array
(
[0] => skos:Concept
)
[name] => Array
(
[predicates] => Array
(
[0] => rdfs:label
[1] => skos:prefLabel
)
)
[description] => Array
(
[predicates] => Array
(
[0] => skos:definition
)
)
[vid] => Array
(
[predicates] => Array
(
[0] => skos:inScheme
)
[type] => rel
)
[parent] => Array
(
[predicates] => Array
(
[0] => skos:broader
)
[type] => rel
)
)
[uri] => Array
(
[path] => taxonomy/term/75
[options] => Array
(
[entity_type] => taxonomy_term
[entity] => stdClass Object
*RECURSION*
)
)
)
)
)
)
Any ideas on how to get things out of the array? I'm not even sure where my output is coming from since it doesn't appear in the array...
Comments
_
If you don't want the html, then don't use render (that's what it does). So based on the example you provided, you should be able to output just the term itself with:
print $content['field_review_nationality']['und'][0][taxonomy_term]->name;
The structure is all there in the sample you provided.
Thanks for your reply. I
Thanks for your reply. I tried this, also trying it with single quotes added around 'taxonomy_term':
I get this error:
Update: I found this.
This prints what I want, but also displays an error message:
Error:
Actually, that error message
Actually, that error message only showed up once and then disappeared. I think it's working now.
Thanks for your help. If I get it sorted out I will write a tutorial...
You gave some great advice to him, could you do the same for me?
Hi WorldFallz :)
I need similar advice. I need to know how to create the right string to display the name of the taxonomy which is BnB Italia in this case.
Im trying to pass the values from a product page to a webform field, so far the first portion is showing correctly but the second is showing only the number of the taxonomy. Could you help at all in showing me the correct structure for this?
Here is how my link in node--product.tpl.php is formatted.
For some reason it tells me that $tid is not a defined variable, but it allows me to use vid.
Just so you know, I'm using Drupal 7, Ubercart, and Webforms.
I thank you in advance for any time taken to see if you can help, it's been about 2 days of struggling :/
hi Useful I.
Have you received any help on this?
Since 'taxonomy_term' is an object (see the label there?), you'll have to use "object notation" which is the single hyphen plus angle bracket to produce an arrow.
So, in this case, assuming this is the output of the $content array, it would be $content['taxonomy_term']->name, so your code would read:
print $content['taxonomy_term']->name;