I've created a custom node.tpl.php for my Bartik subtheme drupal 7 site and wanted to have a headline field wrapped in h2 tags.

I've tried:

<?php if ($content['field_headline']): ?>
    <h2><?php print render($content['field_headline']); ?></h2>
  <?php endif; ?>

which outputs as:

<h2>
<div class="field field-name-field-headline field-type-text field-label-hidden">
<div class="field-items">
<div class="field-item even">This is the headline text</div>
</div>
</div>
</h2>

But I would like it to be:

<h2>This is the headline text</h2>

I don't know anything about php (no kidding, I hear you cry) and the above is just my guesswork. Can anyone help?

Thanks.

Comments

roper.’s picture

I don't know for sure, as I haven't really gotten into D7 myself, but I would try print render($content['field_headline']['value']); ..?

You can also print var_dump($content['field_headline']); to see what's actually in it...

tumbledown100’s picture

Thanks for the response but I'm afraid I don't understand it.

If I swap

<?php if ($content['field_headline']): ?>
    <h2><?php print render($content['field_headline']); ?></h2>
  <?php endif; ?>

for your

<?php
print render($content['field_headline']['value']);
?>

the headline field disappears altogether. Or should I be putting a value in where you've written 'value' ?

Otherwise how would that wrap the field in h2 tags?

I'd be really gratefully if you could dumb this down for me a bit.

Thanks