模块的预处理节点:与template.php没有相同的变量

时间:2011-01-18 21:47:22

标签: drupal drupal-6

我想从模块而不是template.php预处理和设置我的节点。之前,我在theme_preprocess_node()中有一个巨大的switch语句。但这只适用于我的主要标签 - 子标签是从定义的模块中模板化的。所以我喜欢将所有预处理功能和模板合并到一个有组织的模块中。

我想要的结构基本上是这样的(提取摘要的详细信息):

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);
}

一切都很好,但我预处理中可用的$ vars不是我在template.php的theme_preprocess_node()函数中习惯的。例如,看起来CCK字段尚未通过content_format()(没有['view']元素),并且缺少teaserpage等标记。

我可以在theme_preprocess_node()之前调用什么?

我这样做是在惹麻烦吗?让它组织起来并控制每一步对我来说更有意义:菜单>页面回调>主题>预处理>模板,并且能够在我认为合适的情况下跨多个模块组织这个模块。

1 个答案:

答案 0 :(得分:1)

AK,

我的建议是执行以下代码来检查可用的变量

<?php  
$arr = get_defined_vars();  
dsm($arr);  
?>

如果这没有帮助,您可以检查系统表上模块的重量。也许更改它(使模块在其他模块之后运行)可以帮助你。

相关问题