Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By matthias_bauw on
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
ok I found it myself
ok I found it myself
You need to add the &$variables argument to the hook. So the code becomes:
and then I can print the variable $templatepath in page.tpl.php