首页 > 编程知识 正文

freemarker自定义标签,html自定义标签

时间:2023-05-06 04:26:35 阅读:138082 作者:4976

学习写,终于结束了。 顺便分享一下!

taglib是tp框架的定制标记功能。 如果使用过cms的话,一定见过类似的东西吧:

{ dede 3360 arclist typeid=' ' row=' ' col=' ' titlelen=' ' info len=' ' order by=' ' keyword=' ' } SSS . {/dede

或:

{ PC : content action=' lists ' cache=' 3600 ' num=' 20 ' page=' $ page ' } {/PC }

这样的操作对开发工作非常方便。

所以我觉得有必要看tp的taglib。 教程如下所示。

1、common (我在common。 你自己看吧。 反正在命名空间中加载)创建新的目录taglib

2、在taglib上新设Cc.php继承think的Tglib。 代码如下所示。

? PHP/* * * createdbyphpstorm.* user : Li chenchen * date :2018/3/25 * time :34 */namespace appcommon use appcommonmodelArticle; classccextendstaglib { protected $ tags=[ ' articles '=[ ' attr '=' field,id,limit,cid,order,returnname ',' ' $tag['id']:'vo '; $order=empty($tag['order']?' ' id DESC'' : '''.$tag['order'].' '; $returnname='article_data '; $field=" "; if (! empty($tag () field ) ) if ) strpos ) $tag ),($ ) )==0) ) $field=$tag ) ) ) if ); $this-autobuildvar($field ); } else { $field=''{$tag['field']} '; } } $cid=“”; if (! empty($tag('cid ' ) ) if ) strpos ) $tag )、' $ ' ) )==0) ) cid ); $this-autobuildvar($cid ); } else { $cid=''{$tag['cid']} '; } } $limit=“”; if (! empty($tag () limit ) ) if ) strpos ) $tag ),($ ) )==0) ) $limit=$tag ) ) ) limit ); $this-autobuildvar($limit; } else { $limit=''{$tag['limit']} '; } else { $ limit=' 0,5 '; } $parse={$field}、' cid'={$cid}、' limit'={$limit}、' order'={$order} ]; { volist name=' { $ return name } ' id=' { $ id } } { $ content } {/volist } parse; 返回$ parse; }

这里显示了文章标签articles

其中调用了Article模型的静态方法taglib_articles。 顺便把代码也贴上吧。 是根据条件来询问的

publicstaticfunctiontaglib _ articles ($ param ) $field=$param('field ' ); $cid=$param['cid']; $limit=$param['limit']; $order=$param['order']; $ result=article :3360 where (cid ),) in )、$cid )-field )-limit )-order )-sseld return $result; }

请参阅------------------- -请参阅-----------模板路径////模板文件名分隔符' view_depr'=DS,//模板引擎常规标签开始标记' TPL_begg //模板引擎常规标签结束标记' tpl_end'='} ' ' "

现在可以在模板中使用了

{ cc 3360 articles cid='1' field=' id,title ' limit='2' order=' idasc ' id=' VO ' }

{$vo.title} {/cc:articles}很方便吧。 准备了两个小时,终于写了。 我会在这里记录下来。 希望对有需要的朋友们也有帮助。

最近看了flutter,建立了flutter的中文社区。 请看http://www.fluttercn.com

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。