• <tfoot id='kzu0K'></tfoot>
      <bdo id='kzu0K'></bdo><ul id='kzu0K'></ul>

    1. <legend id='kzu0K'><style id='kzu0K'><dir id='kzu0K'><q id='kzu0K'></q></dir></style></legend>

      <small id='kzu0K'></small><noframes id='kzu0K'>

        <i id='kzu0K'><tr id='kzu0K'><dt id='kzu0K'><q id='kzu0K'><span id='kzu0K'><b id='kzu0K'><form id='kzu0K'><ins id='kzu0K'></ins><ul id='kzu0K'></ul><sub id='kzu0K'></sub></form><legend id='kzu0K'></legend><bdo id='kzu0K'><pre id='kzu0K'><center id='kzu0K'></center></pre></bdo></b><th id='kzu0K'></th></span></q></dt></tr></i><div id='kzu0K'><tfoot id='kzu0K'></tfoot><dl id='kzu0K'><fieldset id='kzu0K'></fieldset></dl></div>
      1. 如何在 drupal 7 中实现 hook_theme?

        时间:2023-06-23
        <i id='iE8o6'><tr id='iE8o6'><dt id='iE8o6'><q id='iE8o6'><span id='iE8o6'><b id='iE8o6'><form id='iE8o6'><ins id='iE8o6'></ins><ul id='iE8o6'></ul><sub id='iE8o6'></sub></form><legend id='iE8o6'></legend><bdo id='iE8o6'><pre id='iE8o6'><center id='iE8o6'></center></pre></bdo></b><th id='iE8o6'></th></span></q></dt></tr></i><div id='iE8o6'><tfoot id='iE8o6'></tfoot><dl id='iE8o6'><fieldset id='iE8o6'></fieldset></dl></div>
        <tfoot id='iE8o6'></tfoot>

            <small id='iE8o6'></small><noframes id='iE8o6'>

              <tbody id='iE8o6'></tbody>
              • <bdo id='iE8o6'></bdo><ul id='iE8o6'></ul>
                • <legend id='iE8o6'><style id='iE8o6'><dir id='iE8o6'><q id='iE8o6'></q></dir></style></legend>
                  本文介绍了如何在 drupal 7 中实现 hook_theme?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我创建了一个新的 drupal 7 主题并尝试在 template.php 中实现 hook_theme,如下所示:

                  I created a new drupal 7 theme and trying to implement hook_theme at template.php like this:

                  function mytheme_theme($existing, $type, $theme, $path){
                      return array(
                          'mytheme_header'=>array(
                              'template'=>'header',
                              'path'=>$path.'/templates',
                              'type'=>'theme',
                          ),
                      );
                  }
                  

                  然后我把header.tpl.php放入templates目录并清除所有缓存,并调用主题函数:

                  then I placed header.tpl.php into templates directory and cleared all caches, and call theme function:

                  theme('mytheme_header', $vars);
                  

                  和 header.tpl.php 喜欢这个:

                  and header.tpl.php likes this:

                  <?php
                  fb('calling header template');//the function of FirePHP to output debug info
                  print '<div>Header</div>';
                  //...
                  

                  我检查了 Firebug,它得到信息调用标题模板",这意味着它调用了 header.tpl.php,但它没有打印 html 代码.我的代码有什么问题?

                  I check Firebug and it get the info 'calling header template', it mean it had called header.tpl.php, but it didn't print the html code. What's wrong with my code?

                  推荐答案

                  尝试在hook_theme

                  function mytheme_theme($existing, $type, $theme, $path){
                      return array(
                          'mytheme_header' => array(
                              'template' => 'header',
                              'path' => $path . '/templates',
                              'type' => 'theme',
                              'variables' => array(
                                  'title' => NULL,
                                  'some_text' => NULL,
                              ),
                          ),
                      );
                  }
                  

                  在您的 header.tpl.php 文件中:

                  <h1><?php print $title; ?></h1>
                  <p><?php print $some_text; ?></p>
                  

                  然后,像这样打印出来:

                  Then, print it out like this:

                  $vars = array();
                  $vars['title'] = "This is a title";
                  $vars['some_text'] = "Some text...";
                  print theme('mytheme_header', $vars);
                  

                  这篇关于如何在 drupal 7 中实现 hook_theme?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:脚本运行时php垃圾收集 下一篇:正则表达式从 [简码] 中提取变量

                  相关文章

                  <small id='m6i1s'></small><noframes id='m6i1s'>

                    <bdo id='m6i1s'></bdo><ul id='m6i1s'></ul>

                    <tfoot id='m6i1s'></tfoot>

                    <legend id='m6i1s'><style id='m6i1s'><dir id='m6i1s'><q id='m6i1s'></q></dir></style></legend>
                      <i id='m6i1s'><tr id='m6i1s'><dt id='m6i1s'><q id='m6i1s'><span id='m6i1s'><b id='m6i1s'><form id='m6i1s'><ins id='m6i1s'></ins><ul id='m6i1s'></ul><sub id='m6i1s'></sub></form><legend id='m6i1s'></legend><bdo id='m6i1s'><pre id='m6i1s'><center id='m6i1s'></center></pre></bdo></b><th id='m6i1s'></th></span></q></dt></tr></i><div id='m6i1s'><tfoot id='m6i1s'></tfoot><dl id='m6i1s'><fieldset id='m6i1s'></fieldset></dl></div>