hi there,

I am starting out with template development and I ran into troubles defining a variable for my template.

What i'm trying to do is very simple (I thought):

  • I want to define a variable while preprocessing
  • Then I want to show that variable through page.tpl.php

I have been searching around the forums but now I'm even more confused. I am afraid I mixed up drupal 6 & 7 examples.

I thought that if I defined this function in template.php:

function test2_preprocess(){
    $variables['templatepath'] = 'test';
}

and now I added

print $templatepath;

to page.tpl.php

and I thought that would work but it doesn't...

Comments

matthias_bauw’s picture

ok I found it myself

You need to add the &$variables argument to the hook. So the code becomes:

function test2_preprocess_page(&$variables){
    $variables['templatepath'] = drupal_get_path('theme',$GLOBALS['theme']);
}

and then I can print the variable $templatepath in page.tpl.php