Adding some new custom variables to page.tpl.php I want to add some variables to page.tpl.php via template.php so i guess i need to use my_theme_preprocess_page. But my variables does not seem to be passing through.

I am using something like this :) In template.php

function my_theme_preprocess_page(&amp;$vars) { 
$vars['myvar'] = "value";
}


and in page.tpl.php

print $myvar;


and $myvar fails; also tried defininig it with $vars['page']['myvar'] = "value";
and reading it back with print ($page['myvar']);
but with no luck, variable (or index) stays undefined.

I cleared cache.

Any clues why this does not work ?
Thanks!
Drupal doesn't have code that checks if the theme is adding a new index in the array passed as reference to hook_preprocess_page(); every index added to that array from a preprocess/process function is then passed as PHP variable to the corresponding template file. 

If what you are adding is then not passed to the template file, then the possible explanations are:


You are prefixing the function name with something that is not the short name of the theme.
You wrote the preprocess function for the theme that is not currently active. If the theme currently used is the Bartik theme, the preprocess function for a different theme would not be called. Keep in mind that the used theme could be different from the one you are expecting; this is what happens with administration pages, for which the used theme is the one set as administration theme in admin/appearance.



There are also modules that can set a different theme for a page implementing hook_custom_theme().


A possible mistake could be implementing a preprocess function for a theme when a sub-theme is actually used, or (vice versa) implementing a function for a theme when the parent theme is actually used. 

References


theme()