douxun4860 2012-12-31 10:37
浏览 29
已采纳

渲染存储在page.tpl.php文件中.module文件函数变量中的html数据

I have just started using drupal and am little bit confused with the flow. I have a variable $var = "<div>Render in View</div>" in a function in my .module file. How do I render this exact html in the page.tpl.php file?

Thanks

  • 写回答

1条回答 默认 最新

  • doutao6380 2013-01-02 20:46
    关注

    This might work: http://api.drupal.org/api/drupal/modules%21system%21theme.api.php/function/hook_preprocess/7

    function mymodule_preprocess(&$variables, $hook) {
      if ($hook == 'page') {
        $variables['my_custom_page_var'] = '<div>Render in page.tpl.php</div>';
      }
    }
    

    or use the dynamic hook name

    function mymodule_preprocess_page(&$variables) {
      $variables['my_custom_page_var'] = '<div>Render in page.tpl.php</div>';
    }
    

    Then this should be accessible in page.tpl.php as $my_custom_page_var.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 CSS实现渐隐虚线框
  • ¥15 有没有帮写代码做实验仿真的
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题