thinkphp自定义模板标签(二)
来源:互联网 发布:中世纪2优化9 圣殿骑士 编辑:程序博客网 时间:2024/05/16 01:34
上篇文章已经把自定义标签的准备工作讲完了;那么接下来就是见证...的时候了;没看如何配置的请先移步thinkphp自定义模板标签(一)
闭合标签就是单标签;比如a标签、img标签等等;
非闭合标签就是对标签;比如div、p标签等等;
这里以自定义的ueditor和recommend标签为例;
自定义的闭合标签比较适合用来引文件;
自定义的对标签比较适合调取数据库的数据并前台页面遍历显示;
<?php namespace Common\Tag;use Think\Template\TagLib;class My extends TagLib { // 定义标签 protected $tags=array( // 标签定义: attr 属性列表 close 是否闭合(0 或者1 默认1) alias 标签别名 level 嵌套层次 'ueditor'=> array('attr'=>'name,content','close'=>0), 'recommend'=>array('attr'=>'limit','level'=>1) ); /** *引入ueidter编辑器 *@param string $tag name:表单name content:编辑器初始化后 默认内容 */ public function _ueditor($tag){ $name=$tag['name']; $content=$tag['content']; $link=<<<php<script id="container" name="$name" type="text/plain"> $content</script><script type="text/javascript" src="__PUBLIC__/static/ueditor1_4_3/ueditor.config.js"></script><script type="text/javascript" src="__PUBLIC__/static/ueditor1_4_3/ueditor.all.js"></script><script type="text/javascript"> var ue = UE.getEditor('container');</script>php; return $link; } // 置顶推荐文章标签 cid为空时则抓取全部分类下的推荐文章 public function _recommend($tag,$content){ if(empty($tag['cid'])){ $where="is_show=1 and is_delete=0 and is_top=1"; }else{ $where='is_show=1 and is_delete=0 and is_top=1 and cid='.$tag['cid']; } $limit=$tag['limit']; // p($recommend); $php=<<<php<?php \$recommend=M('Article')->field('aid,title')->where("$where")->limit($limit)->select(); foreach (\$recommend as \$k => \$field) { \$url=U('Home/Index/article',array('aid'=>\$field['aid']));?>php; $php.=$content; //拼字符串的过程。。。 $php.='<?php } ?>';//foreach的回扩; return $php; }}?>
定义完成后在html页面中就可以直接使用<ueditor />即可引入ueditor文件;
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Document</title><ueditor /></head><body> <recommend cid="" limit="10"> <a class="recommend-a" href="{:U('Home/Index/article',array('aid'=>$field['aid']))}" target="_blank">{$k+1}:{$field['title']}</a> </recommend></body></html>
ueditor标签可以直接实例化ueditor编辑器
而如下图本站的热门推荐就是使用recommend遍历的;
0 0
- thinkphp自定义模板标签(二)
- ThinkPHP模板自定义标签使用方法
- thinkphp自定义模板标签(一)
- ThinkPHP模板自定义标签使用方法
- ThinkPHP中自定义模板标签解析
- ThinkPHP自定义函数解决模板标签加减运算
- 【ThinkPHP学习】模板标签
- ThinkPHP 模板标签
- Thinkphp模板标签 For标签
- thinkphp 自定义标签
- ThinkPHP 自定义标签
- thinkphp自定义标签
- ThinkPHP自定义标签
- thinkphp自定义标签
- 【ThinkPHP】自定义标签
- thinkphp自定义标签
- thinkphp 3.2自定义标签
- thinkphp自定义模板函数
- Adam学习之6代码解读kmer.scala(附源码)
- UIButton
- 上海行,重新认识自己
- 【LeetCode】Valid Sudoku
- java BigDecimal 高精度运算 小数点处理详解
- thinkphp自定义模板标签(二)
- iOS UI基础学习历程
- pyqt5载入qml
- spring bean scope 单例与多例
- OnCreateContextMenuListener,MultiChoiceModeListener和OnLongClickListener的优先级
- freemarker模板解析过程
- MySQL 调优/优化的 100 个建议
- JUnit快速入门
- freemarker数据类型