By cschults on
Is it possible to get/access page variables outside of phptemplate_preprocess_page?
For example, within phptemplate_preprocess_page, I can get $vars['node'], but I'd like to access this info from a custom function.
Is it possible to get/access page variables outside of phptemplate_preprocess_page?
For example, within phptemplate_preprocess_page, I can get $vars['node'], but I'd like to access this info from a custom function.
Comments
_
It really depends on exactly what you are trying to achieve.
If your custom function is directly related to a preprocess function, then you would simply pass it from your the preprocess function to your function (yourfunction(&$vars['node'])).
If your function is called from somewhere that doesn't have the variable, you would need to load in the variable using node_load($nid).
For more information about Drupal API functions, refer to: http://api.drupal.org
Trying to avoid node_load()
Thanks Deciphered.
Functions within my theme's template.php need node information, such as node type. I know I can use node_load(), but I was trying to avoid that as that seems inefficient. While I may need to do so in the future, I was able to use the preprocess functions to meet my current needs by saving info to variables.
When calling node_load()
When calling node_load() with just a nid (ex: node_load($nid)), for a given nid, the first time the database is accessed and the node cached. With the same page any additional calls with the same nid simply return the cached node.
Good to know
Thanks nevets.
Yes, if you call the custom
Yes, if you call the custom function from phptemplate_preprocess_page and pass the variable :)
More seriously without knowing the context of how the function is called it is hard to say.