我在用着 module_invoke() 包含一个块,我需要在此块中读取父内容类型页面中包含的值。那么我怎样才能得到 $node 从视图中我的块中的变量?

我正在使用的代码:

<?php
    $block = module_invoke('my_blocks', 'block', 'view', 7);
    print $block['content'];
?>

现在我需要访问 $node 在“my_blocks”中,变量为空。我该怎么做才能得到它?

非常感谢您的帮助!

问候

有帮助吗?

解决方案

小修复可drupal的方式:结果


    function InMODULE_or_InTHEME_get_current_node() {
      if ((arg(0) == 'node') && (is_numeric(arg(1))) && (!arg(2))) return node_load(arg(1));
      return null;
    }

注释:node_load缓存节点,所以不必担心性能比较结果“ARG(2)!”正在检查只是你不要在节点编辑模式(或类似的东西)。

其他提示

我觉得 语境 模块或 混沌工具 可以提供帮助,但这是我最近做同样事情的方法:

function myModule_get_current_node() {
    $path_arr = explode('/', $_GET['q']);
    if ($path_arr[0] == 'node') $result = node_load($path_arr[1]);
    else $result = null;
    return $result;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top