Drupal - 在模板中渲染子视图/部分

Don*_*ply 6 php themes drupal views

如何创建一个html片段,我可以在多个模板页面中重复使用并将变量s传递给?有些人喜欢这样(但显然有点复杂):

<ul>
    <? foreach ($items as $item): ?>
    <li><?=$item?></li>
    <? endfor; ?>
</ul>
Run Code Online (Sandbox Code Playgroud)

谢谢

jml*_*nik 8

使用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
     )
  );
}
Run Code Online (Sandbox Code Playgroud)

在您的模板中:

theme('my_theme_name', array('arg1' => 'val1', 'arg2' => 'val2'));
Run Code Online (Sandbox Code Playgroud)