By newmediaist on
Hey Everyone -
Is it possible / good form to override theme_preprocess_page from within a module? What I'm trying to do in my module is check if there is a parameter in the URL, and if so load a different page theme (stored in the modules directory).
While I figured out how to do this in my theme file, I would like to move the code to a module so it is "template agnostic". I'm guessing something along the following is what I want - hopefully someone can chime in and make sure I'm headed in the right direction?
function phptemplate_preprocess_page(&$variables) {
$path = drupal_get_path('module', 'mycustommodule') .'/theme';
if ($variables['node']->type == "special-node") {
if ($_GET['special-template']) {
$variables['template_files'][] = $path.'/page-node-special';
}
}
}
?>
Thanks!
Comments
function
function [modulename]_preprocess_page()should work I believe. I've used it with preprocessing comments in a module before.Contact me to contract me for D7 -> D10/11 migrations.
I'll give that a try right
I'll give that a try right now - thanks!
ok,
ok, [modulename]_preprocess_page(), but the node object doesn't seem to get loaded into $variables, so I can detect what node type is being shown... is there another more appropriate hook maybe which will return the nodetype?
try the
try the hook_preprocess_node(). it outputs all sorts of cool things on $variables.
here are the first few lines of one of my sites:
notice the [type] in there? that looks like what you are looking for.
perl -e 'print unpack(u,";8F4@=&AE(&-H86YG92P@=7-E(&1R=7!A;\"\$*");'