I'd like to preprocess and theme my nodes from a module instead of template.php. Before, I'd have a giant switch statement in theme_preprocess_node()
. But this only ever applied to my primary tab - subtabs were being templated from the modules they were defined in. So I like the idea of consolidating all my preprocess functions and templates into one organized module.
The structure I want is essentially like this (pulling out details for a summary):
function foomodule_menu()
{
$items['foo/%node'] = array(
'page callback' => 'page_foo_overview',
'page arguments' => array(1),
'type' => MENU_NORMAL_ITEM,
);
$items['foo/%node/overview'] = array(
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['foo/%node/details'] = array(
'page callback' => 'page_foo_details',
'page arguments' => array(1),
'type' => MENU_LOCAL_TASK,
);
}
function foomodule_theme()
{
return array(
'page_foo_overview' => array(
'arguments' => array('node' => NULL),
'template' => 'templates/page-foo-overview'
),
'page_foo_details' => array(
'arguments' => array('node' => NULL),
'template' => 'templates/page-foo-details'
),
);
}
function page_foo_overview($node)
{
// Used to do this, and themed开发者_如何学C it from template.php
// return node_view($node, FALSE, TRUE);
// Instead, I'd like to theme all pages directly in this module:
return theme('page_foo_overview', $node);
}
function template_preprocess_page_foo_overview(&$vars)
{
// But $vars doesn't contain the same data as when I themed from template.php
// Specifically the ['view'] element of CKK fields, and flags like $teaser
// What do I need to do to get at the same data?
dsm($vars);
}
All works great, but the $vars available in my preprocess are not what I'm used to in the template.php's theme_preprocess_node()
function. For one, it looks like CCK fields haven't been run through content_format()
(no ['view'] element), and flags like teaser
and page
are missing.
What's being called before theme_preprocess_node()
that I could invoke here?
Am I asking for trouble by doing this? It makes so much more sense to me to have it organized like this and be in control of each step: menu > page callback > theme > preprocess > template, and to be able to organize this across multiple modules as I see fit.
AK,
My suggestion is to execute the following code to check the available variables
<?php
$arr = get_defined_vars();
dsm($arr);
?>
If that doesn't help you can check the weight of your module on the system table. Maybe changing it (to make your module run after other modules) can help you.
精彩评论