我想从模块,而不是template.php预处理和主题我的节点。之前,我会在theme_preprocess_node()
有一个巨大的开关声明。但是这只适用于我的主选项卡 - 子模块是从它们定义的模块中模板化的。所以我喜欢将所有预处理函数和模板合并到一个有组织模块中的想法。从模块预处理节点:没有得到相同的变量作为template.php
我想要的结构基本上是这样的(拉出细节摘要):
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 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);
}
所有的伟大工程,但$瓦尔在我预处理提供的不是我的习惯template.php的theme_preprocess_node()
函数。例如,看起来CCK字段没有经过content_format()
(no ['view']元素),并且像teaser
和page
这样的标志丢失。
theme_preprocess_node()
之前是什么叫我可以在这里调用?
我是不是要问这个问题?对我来说,让它像这样组织起来,并控制每一步:菜单>页面回调>主题>预处理>模板,并且能够按照我认为合适的方式将其组织在多个模块中。