在application\common\taglib目录下添加My.php文件
<?php
namespace app\common\taglib;
use think\template\TagLib;
class My extends TagLib{
// 定义标签
protected $tags=array(
'jquery'=>array('attr'=>'','close'=>0)
);
//引入jquery
public function _jquery(){
return '<script src="__PUBLIC__/static/js/jquery-2.0.0.min.js"></script>';
}
}
在application\config.php文件添加'taglib_pre_load' => 'app\common\taglib\My'
在模板中调用{My:jquery/}
结果:[1] ErrorException in TagLib.php line 180
Call to undefined method app\common\taglib\My::tagjquery()
if (!empty($tags[0])) {
$regex = $this->getRegex(array_keys($tags[0]), 0);
$content = preg_replace_callback($regex, function ($matches) use (&$tags, &$lib) {
// 对应的标签名
$name = $tags[0][strtolower($matches[1])];
$alias = $lib . $name != $matches[1] ? ($lib ? strstr($matches[1], $lib) : $matches[1]) : '';
// 解析标签属性
$attrs = $this->parseAttr($matches[0], $name, $alias);
$method = 'tag' . $name;
return $this->$method($attrs, '');
}, $content);
}
return;
}
/**
* 按标签生成正则
* @access private
* @param array|string $tags 标签名
按照官方手册,网上搜集的资料都是出现以上的错误提示。声明,在TP3.2.3中没有遇到过这种情况 最佳答案
