I have added a plain text field called "Headline" to all of my content type's to use as an alternate Title for when I add new content to the same page and want to display a updated Title for the node without changing the original Title.

I have altered the theme node.tpl.php file as below.
This prints out the Title as normal if no Text is in the Headline field, and print out the Headline in place of the Title if the Headline field contains Text. The node.tpl.php also prints all other content as normal.

IS this code safe?
IS this the proper Drupal way of doing this?
IS there a better method?

Any help or advise would be grateful.

<article id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<div class="node-inner">
<?php print $unpublished; ?>
<?php if ($title && render ($content['field_headline'])<>""): ?>
<div id = "headline" class = "headline"<?php print $title_attributes; ?>>
<?php if (!$page): ?>
<a href="<?php print $node_url; ?>" rel="bookmark"><?php print render ($content['field_headline']); ?></a>
<?php elseif ($page): ?>
<?php print render ($content['field_headline']); ?>
<?php print $title; ?>
<?php endif; ?>
<?php else: ?>
<div id = "headline" class = "headline"<?php print $title_attributes; ?>>
<?php if (!$page): ?>
<a href="<?php print $node_url; ?>" rel="bookmark"><?php print $title; ?></a>
<?php elseif ($page): ?>
<?php print $title; ?>
<?php endif; ?>
<?php endif; ?>


imranweb’s picture

Its fine as long as you want to show altered title only in node detail page and specific theme.
There is not an any issue with this.
However you could achieve this using node_view hook in your module.


taxicab221’s picture

Thanks for the review Imran.

Yes, this works as I wanted, displaying the Headline instead of the main Node Title when a Headline is added to the post.

Will look at node_view hook and see what I need to achieve the same results.

Again many thanks