【问题标题】:altering footer page on drupal 7在drupal 7上更改页脚页面
【发布时间】:2011-10-10 14:53:12
【问题描述】:

在 Drupal 6 中,我的模块具有下一个函数,该函数将 javascript 插入页面的页脚,但在 Drupal 7 中,情况发生了变化。如何在 drupal 7 中执行下一个代码?

function myfunc_footer()
 {
    if(variable_get('myvar',1) && !drupal_match_path(drupal_get_path_alias($_GET['q']),  
          'admin/*'))
    {
         if ($somevar = variable_get('somevar',''))
             {
        return '<script src="'.$somevar.'" type="text/javascript"></script>';
         }
         else
             {
        drupal_set_message(t('something is wrong.'));
         }
    }
}

提前致谢

【问题讨论】:

    标签: drupal drupal-7


    【解决方案1】:

    您的代码中的任何内容都没有从 Drupal 6 更改为 7...所有功能都是有效的,如果这适用于 Drupal 6,那么它没有理由不适用于 Drupal 7。

    我真的不明白您为什么要针对路径别名运行 drupal_match_path,但您应该针对 router 路径而不是 URL 路径运行它:

    if(variable_get('myvar',1) && !drupal_match_path($_GET['q'], 'admin/*')) {
    

    试试看它是否能解决您的问题,如果不能,您能否详细说明您遇到的错误?

    编辑

    感谢您的更新,您在下面的第二条评论几乎是正确的,您只需给渲染数组一个键:

    function myfunc_page_alter(&$page) { 
      $page['page_bottom']['my_extra_element'] = array(
        '#markup' => '<div><h3> testingthisout</h3> </div>', 
        '#weight' => 25
      ); 
    } 
    

    您不需要指定'#type' =&gt; 'markup',因为markup 是默认值。

    然后确保您的模块(称为myfunc)已确定安装,并清除缓存。从那里你不应该有任何问题

    【讨论】:

    • 您好,从 drupal6 更改为 drupal7。 hook_footer() 已被删除,现在我需要使用我将其命名为 myfunc_page_build() 的 hook_page_build。
    • 我尝试了下一个不起作用的代码: function myfunc_page_build(&$page) { $page['page_bottom']['']= array( '#type' => 'markup' , '#markup' => '

      testingthisout

      ', '#weight' => 25, ); }
    • hook_footer() 被移除,$closure 成为 $page_bottom,$page_top 添加
    • 我已将其更改为您所说的内容,但页面页脚没有打印任何内容。模块已安装。那个 myfunc_page_build 的名字可以吗?名字需要匹配吗?这个函数在哪里被实际调用?
    • 我的错,钩子函数被称为hook_page_alter,所以如果你的模块被称为myfunc,你的函数应该被称为myfunc_page_alter。更改名称后,请务必清除缓存,否则 Drupal 将无法获取它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多