【问题标题】:Drupal - Render a sub view/partial within templateDrupal - 在模板内渲染子视图/部分
【发布时间】:2012-04-05 20:12:40
【问题描述】:

如何创建一个 html sn-p,我可以在多个模板页面中重复使用,并且可以将变量 s 传递到其中?有些像这样(但显然有点复杂):

<ul>
    <? foreach ($items as $item): ?>
    <li><?=$item?></li>
    <? endfor; ?>
</ul>

谢谢

【问题讨论】:

    标签: php drupal views themes


    【解决方案1】:

    在自定义模块中使用hook_theme(),然后在您的模板中调用theme() 方法。

    在你的模块中:

    mymodule_theme($existing, $type, $theme, $path) {
      return array(
        'my_theme_name' => array(
          'template' => 'my_template_file_name', // without the .tpl.php extension
          'variables' => array(), // to define default values for passed variables
         )
      );
    }
    

    在您的模板中:

    theme('my_theme_name', array('arg1' => 'val1', 'arg2' => 'val2'));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-23
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 2013-04-26
      • 1970-01-01
      相关资源
      最近更新 更多