继续Drupal分享精神 QQ群:107748121 站长QQ:2275288328 skype: hellodrupal【drupal交流+drupal 建站+theme制作】
登录 注册

Drupal hook_theme 使用经验

在开发的时候不免要使用到drupal theme 定义。 简单的例子: array( // 给定义的theme 定义一个名称 'arguments' => array('title' => NULL, 'teaser' => NULL, 'link' => NULL), //这些都是要传递的参数,具体是在使用 theme('hot_news',arg1,arg2,arg3),这时使用到。 'template' => 'hot_news', //模板名称,它会自动搜索hot_news.tpl.php模板文件 'file' => 'get_page.inc', //这个是定义相关函数的文件,根据需要自行定义。 'path' =>drupal_get_path('module', 'modulename'), //得到文件路径,如果theme('hot_news',arg)在template.php里面使用,需要告诉drupal具体位置,不定义,如果在template使用,它只能在template.php同目录下查找。默认和主题同目录。 ), ); ?> 每个参数都会写入变量里。 variables.,比如:$variables['title'], $variables['teaser'] and $variables['link']. 接下去就可以使用: 还有一个功能就是预处理机制。 理解hook_theme,就可以自己随心所欲来定制自己的theme。感觉到drupal的强大和灵活了。 总结:我想当告知drupal使用theme('hook',arg)时, 它需要找到hook_theme的定义,如果没有preprocess,那直接把参数送给你tpl.php文件里。如果有,它就把theme('hook',arg)的来参数,传递给preprocess里面,可以直接用$variables['arg']得到值,看看没有重新赋值,如果有,那就使用新的$variables['arg'],最后输出到tpl.php里面。

评论

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 自动断行和分段。
  • You can use BBCode tags in the text.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.