This is similar to Considerations displaying page titles in page or node template which in turn claims to be similar to another question, but the questioner doesn't mention how they achieve what they are doing, and what they are doing may be different from what I'm doing.
In my case, on single node view pages, for certain (most) content-types, there is an optional image field, that needs to be floated left of the title.
I'm not sure if it would be best practice to move the title output down into the node.tpl.php template or to keep it in the page.tpl.php template and load the relevant field for the node in the page template.
This is what I've done:
template.php:
function enviroscope_preprocess_page(&$variables, $hook) {
if (isset($variables['node']->field_doc_cover)) {
$node = node_load($variables['node']->nid);
$output = field_view_field('node', $node, 'field_doc_cover', array('label' => 'hidden'));
$variables['field_doc_cover'] = $output;
}
}
page.tpl.php:
<?php print render($title_prefix); ?>
<?php if ($title): print render($field_doc_cover); ?><h3 class="title" id="page-title"><?php print $title; ?></h3><?php endif; ?>
<?php print render($title_suffix); ?>
This gets the image field printed before the title, but I'm not sure if there is an equivalent here to hide($content['field_doc_cover']);
? Currently this has field_doc_cover
printing twice.
So the main question is,
Is this the right approach?
but this breaks down into some more specific questions:
- Should the title definition stay in page.tpl.php for single node pages?
- If so, is there a good way to exclude the field_doc_cover field from being rendered in the node.tpl.php file without messing with that template too?
- Is there a good reason not to handle the title in the node.tpl.php, and remove it from the page.tpl.php file for these content_types?
- If there is a good reason for it to not be in nodes, would it be sensible to render the element in page.tpl.php and send it as a variable to be used in node.tpl.php?
I'm pretty new to drupal theming as is probably obvious, so examples with your answers would be very helpful!
Update: I was asked to create a visual representation of what I'm trying to do, which was a good call because it reminded me of one more issue: The last modified date should be printed above and to the right of the title.
I guess one of the main things I don't understand is whether there is some good reason why the title needs to be part of the page.tpl.php template. It sure would be easier if it were down in the node template.