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

Drupal theme 自定义简单步骤流程

经常会使用 theme api,比如 theme('image',xxxx),theme('item_list', $items);等等。有事需要自己定义这样的theme. 简单步骤:
1 在使用hook_theme 注册登记一下。叫什么名字。

<?php
/**
*注册theme
*/
function  modulename_theme() {
  return array(
   
'hot_news' => array(
     
'arguments' => array('title' => NULL),//传递给模板里的参数,数字型,对象,数组等等   
     
'template' => 'hot-news',//模板名称,不需要加.tpl.php,程序会自动检索。如果不指定模板路径,默认搜索模块同位置  
   
),

   
'good_news' => array(
     
'arguments' => array('cotent' => NULL),
    ),

  );
}
?>

2、定义theme的输出格式

<?php

function theme_good_news($content){
return
'<div>'.$content .'</div>';
}
?>

3 也可以使用preprocess来先定义好变量。
<?php

function template_preprocess_hot_news($variables){
$variables['output'] = $content;
}
?>

4.这样你就可以使用theme('hot_news',$var);来处理你想要的数据了。

<?php

$output
= "xxxxx";
print
theme('hot_news',$output);
?>

评论

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 自动断行和分段。
  • 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.