文章来源:http://www.imtr.cn/html/n187.html
如果我们想用一个自定义的织梦标签调用内容(例如:{dede:dedecmsok name='hello'/})显然这个标签不是织梦默认的,如果我们想要用它来调用数据,用以下方法可以实现。
新建一个php文件,命名为dedecmsok.lib.php,把php文件放到/include/taglib/文件夹下
<?php if (!defined('DEDEINC')) exit("Request Error!"); function lib_dedecmsok(&$ctag, &$refObj) { global $dsql, $envs; //属性处理 $attlist = "name|"; FillAttsDefault($ctag->CAttribute->Items, $attlist); extract($ctag->CAttribute->Items, EXTR_SKIP); $revalue = $name(); return $revalue; } function hello() { $html = "你好"; return $html; } ?>
在模板中可以用{dede:dedecmsok name='hello'/}来调用,输出内容为“你好”
解释:
{dede:dedecmsok name='hello'/}中的dedecmsok是php文件名dedecmsok.lib.php的前半部分,name='hello'中的hello和第13行的function hello()对应。
注意,php第三行的function lib_dedecmsok(&$ctag, &$refObj)中的dedecmsok要和标签一致才可以哦。
原文地址:http://www.imtr.cn/html/n187.html