0

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?

4

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.

| improve this answer | |
  • 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. – KenAesthetic Dec 30 '11 at 17:54
3

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";
}
| 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.