Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Alperian on
I have been trying to render a ataxonomy term in Drupal. The field name is "field-video-format". All I want output is .mp4 without any tagging and I am unable to render it without the following html:
<div class="field field-name-field-video-format field-type-taxonomy-term-reference field-label-hidden"><div class="field-items"><div class="field-item even">.mp4</div></div></div>
That is using:
print render($content['field_video_format']);
How can I just get the output in the format:
mp4
? I have been read everything I can on this and NO-ONE has a proper answer. Probably because it is an array.
Comments
Why is the html a problem?
Why is the html a problem?
Html
HI. Html is a problem because the output is to be part of a URL
Content without <div> tags
I am pretty sure that you just can type 'print $content['field_video_format'];'
But why are the div-tags a problem?
If you don't like all the div maybe try the Mothership theme https://www.drupal.org/project/mothership
Does not render output
Sadly print $content['field_video_format'] just prints the word 'array' and does not render the output. I have tried Strval, strip_tags.
I cannot change the theme.
Ude devel module
Hi, you have to install the devel module you Can Then use the krumo($content) and get the fuld Path to the value you need.
Or just use print_r(array_values($content))
Customize the field.tpl.php template
You can customize the field.tpl.php template just for your field, I presume it is field-video-format.
You can copy the file field.tpl.php from modules/field/theme into your theme's templates folder
and rename it to field--field_video_format.tpl.php
To show only that mp4 value, probably you can change the contents of that file to:
You can find more details and better explanations here.
To render or not to render....
I know that you aren't supposed to give thanks, but this is not Stackoverflow so here goes:
Many thanks. That was brilliant. I learned stuff as well as getting it sorted.