企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 10. 模板配置JSON ## 模板配置JSON 放在模板的根目录下,用于用户自定义一些配置、前台调取。 支持text、textarea、radio、checkbox、select、image、images、date、datetime控件 组件可前往这里了解:[字段类型与组件](Qian%20Yan.html) ## 使用说明 ### 一级写法 说明 ![](https://img.kancloud.cn/87/a0/87a00a8abf20e7d2802626228b2e25eb_349x259.png) key更改key值value值是否必填说明field可更改--field改为king 前台调用方式 {$Tpl.king}title否随便填否-type否text textarea radio checkbox select image images date datetime---具体说明 [字段类型与组件](Qian%20Yan.html)tips否随便填否后台模板配置时候提示效果rules否-否验证规则 如果多个验证请用 ; 隔开 [查看规则](Yan%20Zheng%20Gui%20Ze.html)error\_tips否随便填否自定义验证规则错误信息。 填写了,会覆盖规则的错误提示消息。value否-否默认值### 多级写法 说明 ![](https://img.kancloud.cn/1b/f8/1bf8887abd75f74721ff8526d07431c8_409x504.png) key更改key值value值是否必填说明base/more可更改--base改为king 前台调用方式 {$Tpl.king.item中的key值}title否随便填否-item否-是多个一级写法组成 key值不能重复## 使用示例 ### 简单写法(一级) 前台调用方式,如下配置文件。调取标题字段的值。 **{$Tpl.field}** 或者 **{$Tpl\['field'\]}** ``` <pre class="calibre16">``` <span class="token1">{</span> <span class="token4">"field"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"标题"</span><span class="token1">,</span> <span class="token4">"type"</span><span class="token1">:</span> <span class="token4">"text"</span><span class="token1">,</span> <span class="token4">"tips"</span><span class="token1">:</span> <span class="token4">"提示"</span><span class="token1">,</span> <span class="token4">"rules"</span><span class="token1">:</span> <span class="token4">"required;length(3~16)"</span><span class="token1">,</span> <span class="token4">"error_tips"</span><span class="token1">:</span> <span class="token4">"值必须"</span><span class="token1">,</span> <span class="token4">"value"</span><span class="token1">:</span> <span class="token4">""</span> <span class="token1">}</span> <span class="token1">}</span> ``` ``` 效果图 ![](https://img.kancloud.cn/c8/7c/c87c00878c38732294a020a9cd8a533b_803x252.jpg) ### 配置分组写法 (多级) 调取标题 **{$Tpl.base.text}** 或者 **{$Tpl\['base'\]\['text'\]}** 示例代码 ``` <pre class="calibre16">``` <span class="token1">{</span> <span class="token4">"base"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"基础配置"</span><span class="token1">,</span> <span class="token4">"item"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"text"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"标题"</span><span class="token1">,</span> <span class="token4">"type"</span><span class="token1">:</span> <span class="token4">"text"</span><span class="token1">,</span> <span class="token4">"tips"</span><span class="token1">:</span> <span class="token4">"提示"</span><span class="token1">,</span> <span class="token4">"rules"</span><span class="token1">:</span> <span class="token4">"required;length(3~16)"</span><span class="token1">,</span> <span class="token4">"error_tips"</span><span class="token1">:</span> <span class="token4">"值必须"</span><span class="token1">,</span> <span class="token4">"value"</span><span class="token1">:</span> <span class="token4">""</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"textarea"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"描述"</span><span class="token1">,</span> <span class="token4">"type"</span><span class="token1">:</span> <span class="token4">"textarea"</span><span class="token1">,</span> <span class="token4">"tips"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"rules"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"error_tips"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"value"</span><span class="token1">:</span> <span class="token4">""</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"radio"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"是否显示"</span><span class="token1">,</span> <span class="token4">"type"</span><span class="token1">:</span> <span class="token4">"radio"</span><span class="token1">,</span> <span class="token4">"tips"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"rules"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"error_tips"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"options"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"1"</span><span class="token1">:</span> <span class="token4">"显示"</span><span class="token1">,</span> <span class="token4">"0"</span><span class="token1">:</span> <span class="token4">"不显示"</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"value"</span><span class="token1">:</span> <span class="token4">"1"</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"checkbox"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"多项选择"</span><span class="token1">,</span> <span class="token4">"type"</span><span class="token1">:</span> <span class="token4">"checkbox"</span><span class="token1">,</span> <span class="token4">"tips"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"rules"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"error_tips"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"options"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"1"</span><span class="token1">:</span> <span class="token4">"显示1"</span><span class="token1">,</span> <span class="token4">"2"</span><span class="token1">:</span> <span class="token4">"显示3"</span><span class="token1">,</span> <span class="token4">"0"</span><span class="token1">:</span> <span class="token4">"不显示"</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"value"</span><span class="token1">:</span> <span class="token4">"1,2"</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"select"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"下拉选择"</span><span class="token1">,</span> <span class="token4">"type"</span><span class="token1">:</span> <span class="token4">"select"</span><span class="token1">,</span> <span class="token4">"tips"</span><span class="token1">:</span> <span class="token4">"我是提示"</span><span class="token1">,</span> <span class="token4">"rules"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"error_tips"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"options"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"1"</span><span class="token1">:</span> <span class="token4">"测试1"</span><span class="token1">,</span> <span class="token4">"2"</span><span class="token1">:</span> <span class="token4">"测试2"</span><span class="token1">,</span> <span class="token4">"3"</span><span class="token1">:</span> <span class="token4">"测试3"</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"value"</span><span class="token1">:</span> <span class="token4">"2"</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"selects"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"下拉多项选择"</span><span class="token1">,</span> <span class="token4">"type"</span><span class="token1">:</span> <span class="token4">"selects"</span><span class="token1">,</span> <span class="token4">"tips"</span><span class="token1">:</span> <span class="token4">"我是提示"</span><span class="token1">,</span> <span class="token4">"rules"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"error_tips"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"options"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"1"</span><span class="token1">:</span> <span class="token4">"测试1"</span><span class="token1">,</span> <span class="token4">"2"</span><span class="token1">:</span> <span class="token4">"测试2"</span><span class="token1">,</span> <span class="token4">"3"</span><span class="token1">:</span> <span class="token4">"测试3"</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"value"</span><span class="token1">:</span> <span class="token4">"2,3"</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"more"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"更多选项"</span><span class="token1">,</span> <span class="token4">"item"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"image"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"图片"</span><span class="token1">,</span> <span class="token4">"type"</span><span class="token1">:</span> <span class="token4">"image"</span><span class="token1">,</span> <span class="token4">"tips"</span><span class="token1">:</span> <span class="token4">"请上传图片"</span><span class="token1">,</span> <span class="token4">"rules"</span><span class="token1">:</span> <span class="token4">"required"</span><span class="token1">,</span> <span class="token4">"error_tips"</span><span class="token1">:</span> <span class="token4">"请上传图片"</span><span class="token1">,</span> <span class="token4">"value"</span><span class="token1">:</span> <span class="token4">""</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"images"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"图片"</span><span class="token1">,</span> <span class="token4">"type"</span><span class="token1">:</span> <span class="token4">"images"</span><span class="token1">,</span> <span class="token4">"tips"</span><span class="token1">:</span> <span class="token4">"请上传图片"</span><span class="token1">,</span> <span class="token4">"rules"</span><span class="token1">:</span> <span class="token4">"required"</span><span class="token1">,</span> <span class="token4">"error_tips"</span><span class="token1">:</span> <span class="token4">"请上传图片"</span><span class="token1">,</span> <span class="token4">"max_number"</span><span class="token1">:</span> <span class="token3">5</span><span class="token1">,</span> <span class="token4">"value"</span><span class="token1">:</span> <span class="token4">""</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"date"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"日期"</span><span class="token1">,</span> <span class="token4">"type"</span><span class="token1">:</span> <span class="token4">"date"</span><span class="token1">,</span> <span class="token4">"tips"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"rules"</span><span class="token1">:</span> <span class="token4">"required"</span><span class="token1">,</span> <span class="token4">"error_tips"</span><span class="token1">:</span> <span class="token4">"日期选择"</span><span class="token1">,</span> <span class="token4">"value"</span><span class="token1">:</span> <span class="token4">""</span> <span class="token1">}</span><span class="token1">,</span> <span class="token4">"datetime"</span><span class="token1">:</span> <span class="token1">{</span> <span class="token4">"title"</span><span class="token1">:</span> <span class="token4">"日期时间"</span><span class="token1">,</span> <span class="token4">"type"</span><span class="token1">:</span> <span class="token4">"datetime"</span><span class="token1">,</span> <span class="token4">"tips"</span><span class="token1">:</span> <span class="token4">"日期时间"</span><span class="token1">,</span> <span class="token4">"rules"</span><span class="token1">:</span> <span class="token4">""</span><span class="token1">,</span> <span class="token4">"error_tips"</span><span class="token1">:</span> <span class="token4">"日期时间"</span><span class="token1">,</span> <span class="token4">"value"</span><span class="token1">:</span> <span class="token4">""</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token1">}</span> ``` ``` 分组后的效果图 ![](https://img.kancloud.cn/81/74/8174709ca8e948bef7965c2261411f93_1193x825.png)