I am trying to move the first chunk of code including the PHP logo call, and the breadcrumbs into the header region. I have created the block, and made it capable of reading PHP. I understand I need to write a preprocess function in template.php, but I am not sure how this is done. I am working in Drupal 7.

Can anyone show me an example, and explain how this works, or point me in the right direction?

2 Answers 2


Defining a variable in a template_preprocess() function is straightforward:

* Implements hook_preprocess().
function yourthemename_preprocess(&$variables, $hook) {

    $variables['your_variable_name'] = "some value";


In your template file, you would just output it directly, for example using the following code:

<?php print $your_variable_name; ?>

I'm not sure this answers your real question, but I could use a little more information. Why are you trying to move the logo/breadcrumbs using a preprocess function? Which theme are you using? If you're moving these around, it is usually easier to just edit the page.tpl.php file in your theme, and work with them from there.

  • Yea maybe I should just leave them in the page.tpl file. I thought it made more sense to use the regions the way the page is built but seems more trouble than it is worth. I also wanted to be able to edit the header block and it update on all pages as I have a few template files to edit when It comes to making an update. I am using the a sub-theme of Zen. Dec 30, 2011 at 17:54

Just an addition to your answer: Depending on the use case, you have to use a more granular preprocess hook. Using the hook in your example, the page performance seems highly decreased. And it does not work for me in the page.tpl at all.

This work´s for me:

function THEMENAME_process_page(&$variables) {
  $variables['your_variable_name'] = "some value";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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