在开发的时候不免要使用到
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里面。
评论
发表新评论