文档:方法及参数

文档:方法及参数

方法及参数

基本

执行代码,当返回

示例:

html
 
{> $a=1}
1

赋值

示例:

html
 
{$a=1}
1

输出

示例:

html
  
{=$a}
{$a} // 这种不能包含 = 
12

文本块

示例:

html
     
{>js}

$(this).val();

{/>}
12345

资源文件引用

示例:

html
    
{js:min.js}
{css:style.css}

{@min.js}
1234

if

判断语句

  1. 判断 示例:
    html
           
    {if:$cat}
    <div></div>
    {elseif:$item}
    <div></div>
    {else:}
    <div></div>
    {/if}
    1234567

    可以简写

    html
           
    {| $cat}
    <div></div>
    {+ $item}
    <div></div>
    {+}
    <div></div>
    {-}
    1234567
  2. 一行执行
参数 类型 必填 说明
$con any 是 条件语句
$echo any 否 判断为true时输出此语句
$echo2 any 否 判断为false时输出此语句

一个参数 示例:

html
 
{if:$cat,ddd}
1

相当于

html
   
{if:$cat}
{=ddd}
{/if}
123

两个参数

示例:

html
 
{if:$cat,ddd,fff}
1

相当于

html
     
{if:$cat}
{=ddd}
{else:}
{=fff}
{/if}
12345

for

循环遍历数据

  1. 一个参数时

循环判断参数是否为 true, 请注意死循环

示例:

html
    
{for:$cat}

    {$cat=false}
{/for}
1234
  1. 两个参数时

第二个参数可为空

参数 类型 必填 说明
$data array 是 条件语句
$key 变量名 否 默认为 $item

示例:

html
   
{for:$cat,}
    {$item}
{/for}
123
  1. 三个参数时
参数 类型 必填 说明
$data array 是 条件语句
$key 变量名 是 变量名
$con 判断语句 是 不需要填前置变量

示例:

html
   
{for:$cat,$item,>=1}
    {$item}
{/for}
123

相当于

html
     
{for:$cat,$item}
    {if:$item>=1}
        {$item}
    {/if}
{/for}
12345

当第三个参数为数字时

示例:

html
   
{for:$cat,$item,10}
    {$item} // 变量前10个
{/for}
123

当第二个参数为判断语句时

示例:

html
   
{for:$i,$i<10,$i++}
    {$i}
{/for}
123

简写示例:

html
   
{~ $cat}

{/~}
123

switch

  1. 一个参数时

示例:

html
      
{switch:$cat}
    {case:true}
        {break:}
    {default:}

{/switch}
123456
  1. 两个参数时
html
   
{switch:$cat,true}
TODO
{/switch}
123

相当于

html
    
{switch:$cat}
    {case:true}
        TODO
{/switch}
1234

注册方法

isset

判断变量是否定义

参数 类型 必填 说明
$param 变量 是 必须是变量

示例:

html
   
{if:isset:$cat}

{/if}
123

empty

判断变量的值是否为空

参数 类型 必填 说明
$param 变量 是 必须是变量

示例:

html
   
{if:empty:$cat}

{/if}
123

__

翻译文本

参数 类型 必填 说明
$key string 是
$params array 否 替换翻译文字中的内容

示例:

html
   
{__:key}

{__:key,a=>$a}
123

url

输出链接

参数 类型 必填 说明
$path string 是
$queries array 否 查询参数

示例:

html
    
{url:./}

{url:./,a=>$a}
{url:./aa:$a:/b,a=>$a}
1234

text

格式化输出,转义html标记

参数 类型 必填 说明
$data string 是

示例:

html
 
{text:$html}
1

channel

获取栏目的信息

参数 类型 必填 说明
$id string,int 是 int 为后台添加时生成的,字符串是自己定义的
$key string 否 栏目的字段名

示例:

html
   
{$cat=channel:product}
{$cat=channel:1}
{channel:product,name}
123

channelRoot

获取根栏目

参数 类型 必填 说明
$id string,int 是

示例:

html
 
{$cat=channelRoot:product}
1

channelActive

判断栏目是否是当前栏目,是则输出 active

参数 类型 必填 说明
$id string,int 是

示例:

html
 
{channelActive:product}
1

content

获取内容的信息,比如输出指定文章的链接

参数 类型 必填 说明
$id array,int 是
$key string 否 文章的字段名
$channel string,int 否 栏目

示例:

html
 
{content:$data}
1

formContent

获取表单的信息

参数 类型 必填 说明
$model string,int 是
$name string 否 字段名
$channel string,int 否 栏目
$user string,int 否 用户id

示例:

html
 
{$data=formContent:name}
1

field

获取当前模型的字段信息

参数 类型 必填 说明
channel string,int 否 栏目
name string,int 否 字段名

示例:

html
 
{$data=field:channel=>name}
1

markdown

markdown 输出为html

参数 类型 必填 说明
content string 是 字符串

示例:

html
 
{markdown:$content.content}
1

formAction

输出表单提交的网址

参数 类型 必填 说明
id string,int 是 模型的表名

示例:

html
 
{formInput:$item}
1

formInput

输出表单输入框

参数 类型 必填 说明
$data array 是 字段信息

示例:

html
 
{formInput:$item}
1

location

输出当前导航路径信息

示例:

html
 
{location:}
1

previous

前一篇文章

示例:

html
 
{$prev=previous:}
1

next

后一篇文章

示例:

html
 
{$next=next:}
1

option

站点获取配置信息

参数 类型 必填 说明
code string 是 配置的别名
type string 否 转成什么内容,例如 number 则提取值中的数字

示例:

html
 
{option:logo}
1

contentUrl

输出内容页的地址

参数 类型 必填 说明
data array 是 文章的数据

示例:

html
 
{contentUrl:$content}
1

search

生成搜索链接

参数 类型 必填 说明
name string 是 参数名
value string 是 参数值

示例:

html
 
{search:name,k}
1

searchActive

判断当前网址是否包含参数值, 包含输出active

参数 类型 必填 说明
name string 是 参数名
value string 是 参数值

示例:

html
 
{searchActive:name,k}
1

searchHidden

为搜索表单添加当前网址的参数

示例:

html
 
{searchHidden:}
1

commentHidden

为评论表单添加文章的参数

示例:

html
 
{commentHidden:}
1

linkageText

获取联动项的完整路径

参数 类型 必填 说明
id int 是 子项id

示例:

html
 
{linkageText:$item.id}
1

extendContent

对当前栏目获取的分页文章追加查询副表数据

参数 类型 必填 说明
$data array,Page 是 分页数据
...field string 是 字段

示例:

html
 
{extendContent:$page,k,z,d}
1

extendForm

获取表单

参数 类型 必填 说明
id string,int 是 模型的表名

示例:

html
 
{extendForm:name}
1

regex

正则提取某个值

参数 类型 必填 说明
input string 是 需要匹配的值
pattern string 是 正则表达式
tag string,int 否 提取的结果的tag

示例:

html
 
{regex:$content.file,'/\d+/'}
1

authGuest

是否是未登录

示例:

html
  
{if:authGuest:}
{/if}
12

authUser

获取当前登录账户信息

示例:

html
 
{$user=authUser:}
1

fileName

获取文件的原始文件名

参数 类型 必填 说明
url string 是 当前文件上传后的地址

示例:

html
 
{fileName:$content.file}
1

pager

输出分页链接

示例:

html
 
{pager:}
1

注册方法块

comments

获取评论

参数 类型 必填 说明
article int 否 文章的id
model string,int 否 模型
channel string,int 否 栏目,和 model article 三选一
keywords string 否 搜索
parent int 否 主文章的id
extra string 否 需要哪些字段值,以英文逗号,分割
order string 否 以哪些字段值排序,以英文逗号,分割,正序倒序方式为空格或_加desc或asc
num int 否 需要个数。无分页数据
per_page int 否 需要个数, 使用此参数会带有分页数据
page int 否 第几页

返回值 $content:array 数据字段;

示例:

html
   
{contents:channel=>product_sample,product_id=>$data.id,field=>'id,cat_id,model_id,title,file',num=>5}
{$content.title}
{/contents}
123

channels

获取栏目

参数 类型 必填 说明
children string,int 否 模型名
group string 否 摸一个分组
parent string 否 摸一个分组
tree any 否 转成树形结构
id string,int 否 排除某几个栏目,以英文逗号,分割

返回值 $content:array 数据字段;

示例:

html
    
// 获取导航分组下的栏目
{channels:tree=>1,group=>nav}
{$channel.name}
{/channels}
1234

contents

获取文章

参数 类型 必填 说明
model string,int 否 模型名
channel string,int 否 栏目名,和 model 二选一
keywords string 否 搜索关键词
parent int 否 主文章的id
field string 否 需要哪些字段值,以英文逗号,分割
order string 否 以哪些字段值排序,以英文逗号,分割,正序倒序方式为空格或_加desc或asc
num int 否 需要个数。无分页数据
per_page int 否 需要个数, 使用此参数会带有分页数据
page int 否 第几页
.. string,int 否 其他字段的过滤值

返回值 $content:array 数据字段;

示例:

html
   
{contents:channel=>product_sample,product_id=>$data.id,field=>'id,cat_id,model_id,title,file',num=>5}
{$content.title}
{/contents}
123

formColumns

获取表单的每一个字段

参数 类型 必填 说明
id string,int 是 表单模型的表名

返回值 $item:array 模型的字段属性及值;

示例:

html
           
{formColumns:prouct_type}
    {if:$item.type == 'textarea' || $item.type == 'editor'}
    <div class="col-md-12">
        {formInput:$item}
    </div>
    {else}
    <div class="col-md-6">
        {formInput:$item}
    </div>
    {/if}
{/formColumns}
1234567891011

linkage

获取多级联动菜单项

参数 类型 必填 说明
id string,int 是 联动项的别名
dataId int 否 获取一个子项的数据
key string 否 获取一个子项的一个字段值
  1. 一个参数时,返回值 $item:array 联动项的树形结构;
  2. 二个参数时,返回值 $item:array 联动项的数据;
  3. 三个参数时,返回值 $item:string 联动项的数据某一项的值;

示例:

html
      
{linkage:prouct_type}
{$item.name}
    {for:$item.children,$it}
        {$it.name}
    {/for}
{/linkage}
123456

range

获取1到4的连续整数

参数 类型 必填 说明
start string,int 是 起始值,为字符串表示取日期的格式 date('Y')
end string,int 是 结束值
step int 否 步进间隔

返回值 $item:int 数据字段;

示例:

html
    
// 获取从2000到今年的年份循环值
{range:2000,Y,1}
{$item}
{/range}
1234

contentPage

获取文章列表分页

与 contents 的区别 : contentPage 会自动获取当前网址的分页数据

参数 类型 必填 说明
model string,int 否 模型名
channel string,int 否 栏目名,和 model 二选一
keywords string 否 搜索关键词
parent int 否 主文章的id
field string 否 需要哪些字段值,以英文逗号,分割
order string 否 以哪些字段值排序,以英文逗号,分割,正序倒序方式为空格或_加desc或asc
num int 否 需要个数。无分页数据
per_page int 否 需要个数, 使用此参数会带有分页数据
page int 否 第几页
.. string,int 否 其他字段的过滤值

返回值 $content:array 数据字段;

示例:

html
   
{contentPage:channel=>product_sample,product_id=>$data.id,field=>'id,cat_id,model_id,title,file',num=>5}
{$content.title}
{/contentPage}
123