模板标签
- 内置标签:include,import,volist,foreach,for,switch,compare,present,empty,defined,if/else
- 输出php代码:PHP标签
- 原样输出:literal标签<literal></literal>标签是避免解析
标签库
- 使用taglib标签<taglib name="ViewsTagLibJike"/><Jike:friends name="jike_user" uid="2"></Jike:friends>
- 标签库的加载:taglib标签,标签预加载配置(TAGLIB_PRE_LOAD)'TAGLIB_PRE_LOAD'=>'ViewsTagLibJike' <Jike:friends name="jike_user" uid="2"></Jike:friends>
- 配置内置标签库:'TAGLIB_BUILD_IN'=>'ViewsTagLibJike' <friends name="jike_user" uid="2"></friends>
如何自定义标签库:
打开 Thinkphp/Library/Think/Template/TagLib/Cx.class.php
在网站的应用目录下创建一个标签的类文件
<?php namespace ViewsTagLib; use ThinkTemplateTagLib; class Jike extends TagLib { //定义标签列表 protected $tags=array( 'friends'=>array( 'attr'=>'uid', 'close'=>1 ) ); public function _friends($tag,$content) { $id=$tag['uid']; $name=$tag['name']; $empty=$tag['empty']; $unique=rand(); $parse_string='<?php'; $parse_string='$_FRIENDS_'$unique'=get_user_friends('$id');'; $parse_string='if(empty($_FRIENDS_'$unique')){echo $empty;}'; $parse_string='else'; $parse_string='{'; $parse_string='foreach($_FRIENDS_'$unique' as $key=>$'$name'){'; $parse_string='?>'; $parse_string=$content; $parse_string='<?php'; $parse_string='}'; $parse_string='}'; $parse_string='?>'; return $parse_string; } }