代码之家  ›  专栏  ›  技术社区  ›  cgp

Drupal:如何在模块中调用模板?

  •  2
  • cgp  · 技术社区  · 14 年前

    我有一些 非节点

    我想我可以做些什么:

    $html = theme('verysmallsnippet', $my_fancy_data_structure);
    

    …然后创建 verysmallsnippet.tpl.php 在活动主题文件夹中的文件,然后期望Drupal找到模板文件并使用传递给主题函数的参数计算模板。这是对模板引擎工作方式的一种过于简单的解释吗?还是我需要先设置主题注册表?或者什么?

    我看了看 this question ,以及 theme

    1 回复  |  直到 7 年前
        1
  •  3
  •   Henrik Opel    14 年前

    是的,稍微过于简单化了;)

    Theming Guide ,并根据您的具体需要,检查 Using the theme layer (Drupal 6.x) .

    为了让您的示例工作,您需要通过实现 hook_theme() :

    function yourModule_theme($existing, $type, $theme, $path) {
      $items = array();
      $items['verysmallsnippet'] = array(
        'arguments' => array('my_fancy_data_structure' => array()), // Change array() to a fitting default
        'template' => 'verysmallsnippet',
      );
    
      return $items;
    }
    

    注: