0

In my D7 template I have a tpl file called:

html--events.tpl.php

  <html class="no-js" lang="<?php print $language->language; ?>" dir="<?php print $language->dir; ?>"<?php print $rdf_namespaces; ?>>
<?php endif; ?>
<head>
  <?php print $head; ?>
  <title><?php print $head_title; ?></title>
  <?php print $styles; ?>
  <?php print $scripts; ?>
</head>
<body<?php print $attributes;?>>
  <a href="#main-content" class="element-invisible element-focusable"><?php print t('Skip to main content'); ?></a>

  <?php print $page_top; ?>
  <?php print $page; ?> 
  <?php print $page_bottom; ?>

</body>
</html>

I would like to add a page header image to this page by changing the template.

So therefore I would like to split the rendered content of this page for e.g. like this:

  <?php print $page_top; ?>
  <?php print $pageheader; ?> 
  <?php print "<div><img src='sites/default/files/animage.png'>/div>" ?> 
  <?php print $pagetitle; ?> 
  <?php print $pagemaincontnet; ?> 
  <?php print $page_bottom; ?>

However the var $page contains already all the rendered header. How can I split the rendered page into smaller blocks? I tried to replace:

<?php print $page; ?> 

into

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

but then got a message : Only variables can be passed by reference

Any suggestion is very welcome.

1

$page is the rendered content from page.tpl.php - you can't alter it in the HTML template without resorting to nasty string manipulation.

Fortunately your desired output lends itself nicely to being handled in the page template anyway. You won't automatically have the same template name suggestions available, although a theme/module might already make them available in your installation. If not, you can add it yourself:

function MYTHEME_preprocess_page(&$vars) {
  // This condition may need to change depending on your exact needs
  if (arg(0) == 'events' && !arg(1)) {
    $vars['theme_hook_suggestions'][] = 'page__events';
  }
}

Then in page--events.tpl.php you'll have access to the individual elements of the $page array, and you can render them as needed.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.