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

nevets’s picture

Why is the html a problem?

Alperian’s picture

HI. Html is a problem because the output is to be part of a URL

dafnie’s picture

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

Alperian’s picture

print $content['field_video_format']

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.

dafnie’s picture

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))

arrakis83’s picture

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:

<?php foreach ($items as $delta => $item): ?>
  <?php print render($item); ?>
<?php endforeach; ?>

You can find more details and better explanations here.

Alperian’s picture

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.