We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHP版本:8.3.10 ThinkPHP版本:8.0.4 标签库:Cms.php
8.3.10
8.0.4
<?php namespace app\common\taglib; use think\facade\View; use think\template\TagLib; use hulang\tool\FileHelper; class Cms extends TagLib { /** * 定义标签列表 */ protected $tags = [ // 标签定义: attr 属性列表 close 是否闭合(0 或者1 默认1) alias 标签别名 level 嵌套层次 'select' => ['attr' => 'param,value', 'close' => 1], 'radio' => ['attr' => 'param,value', 'close' => 1], 'checkbox' => ['attr' => 'param,value', 'close' => 1], ]; /** * 下拉选择组件 */ public function tagSelect($tag, $content) { // region|区域|江苏省:1,浙江省:2,山东省:3,湖北省:4,湖南省:5 $param = trim($tag['param']); $paramArr = str2arr($param, '|'); // 默认值 $value = empty(trim($tag['value'])) ? 0 : trim($tag['value']); // 读取模版 $path = join(DIRECTORY_SEPARATOR, [getStaticPath(0), 'tag', 'cms', 'select.html']); $template = FileHelper::readFile($path); // 解析数组 $arr = str2arr($paramArr[2]); $list = []; foreach ($arr as $k => $v) { $dt = str2arr($v, ':'); $list[$k]['name'] = $dt[0]; $list[$k]['value'] = $dt[1]; $list[$k]['checked'] = 0; if (trim($value) == trim($dt[1])) { $list[$k]['checked'] = 1; } } // 解析模版 $data = [ 'value' => $value, 'name' => $paramArr[0], 'title' => $paramArr[1], 'list' => $list, ]; $html = View::display($template, $data); // 返回模板 return $html; } /** * 单选按钮组件 */ public function tagRadio($tag, $content) { // gender|性别|男:1,女:2,不填:3 $param = trim($tag['param']); $paramArr = str2arr($param, '|'); // 默认值 $value = empty(trim($tag['value'])) ? 0 : trim($tag['value']); // 读取模版 $path = join(DIRECTORY_SEPARATOR, [getStaticPath(0), 'tag', 'cms', 'radio.html']); $template = FileHelper::readFile($path); // 解析数组 $arr = str2arr($paramArr[2]); $list = []; foreach ($arr as $k => $v) { $dt = str2arr($v, ':'); $list[$k]['name'] = $dt[0]; $list[$k]['value'] = $dt[1]; $list[$k]['checked'] = 0; if (trim($value) == trim($dt[1])) { $list[$k]['checked'] = 1; } } // 解析模版 $data = [ 'value' => $value, 'name' => $paramArr[0], 'title' => $paramArr[1], 'list' => $list, ]; $html = View::display($template, $data); // 返回模板 return $html; } /** * 复选框组件 */ public function tagCheckbox($tag, $content) { // area|行政区域|南京:1,北京:2,上海:3,深圳:4,广州:5 $param = trim($tag['param']); $paramArr = str2arr($param, '|'); // 默认值 $value = empty(trim($tag['value'])) ? 0 : trim($tag['value']); // 读取模版 $path = join(DIRECTORY_SEPARATOR, [getStaticPath(0), 'tag', 'cms', 'checkbox.html']); $template = FileHelper::readFile($path); // 解析数组 $arr = str2arr($paramArr[2]); $list = []; foreach ($arr as $k => $v) { $dt = str2arr($v, ':'); $list[$k]['name'] = $dt[0]; $list[$k]['value'] = $dt[1]; $list[$k]['checked'] = 0; if (trim($value) == trim($dt[1])) { $list[$k]['checked'] = 1; } } // 解析模版 $data = [ 'value' => $value, 'name' => $paramArr[0], 'title' => $paramArr[1], 'list' => $list, ]; $html = View::display($template, $data); // 返回模板 return $html; } }
配置文件config/view.php
config/view.php
// 自定义标签 'taglib_pre_load' => 'app\common\taglib\Cms',
模版中调用: {cms:select}{/cms:select}
{cms:select}{/cms:select}
提示错误: 模板标签错误:select
模板标签错误:select
哪里我写错了?也不进入tagSelect方法中。。。没法调试。。。
tagSelect
The text was updated successfully, but these errors were encountered:
已解决。。。
Sorry, something went wrong.
No branches or pull requests
PHP版本:
8.3.10
ThinkPHP版本:
8.0.4
标签库:Cms.php
配置文件
config/view.php
模版中调用:
{cms:select}{/cms:select}
提示错误:
模板标签错误:select
哪里我写错了?也不进入
tagSelect
方法中。。。没法调试。。。The text was updated successfully, but these errors were encountered: