0

I need to initialize some variables in a preprocessor function. I know for page template i can use mytheme_preprocess_page.

I have a custom page template page--mycustompage.tpl.php. I want to preprocess some variables only for that template. Is there and option like mytheme_preprocess_page_mycustompage(&$vars)?

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
Abhishek
  • 157
  • 1
  • 4
  • 13
  • Just IMHO: this is logically incorrect. Preprocessing is not a place where you should check which data will be available for which template based on template suggestion result. If you want to do this because of access control then you should do it in your module code based not on which template was selected but on which URL is used/which user is logged in/ which roles does he have and so on. You should theme it somewhere else (in your module etc) and then just assign it in preprocess() no matter which template is selected. Then just do the output in right template. – Alex Smirnoff Sep 04 '12 at 08:23

1 Answers1

1

I think you should try the following code:

function mytheme_preprocess_page(&$vars)
{
    if(arg(0) == "mycustompage" && is_null(arg(1)))
    {
        // Your code goes here...
    }
}

Kindly note that, I'm assuming that "mycustompage" is the path to your page.

Hope it works... Muhammad.

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105