PaYphp 为个人企业提供全方位的支付解决方案
templates/pay/
└─ [主题名称]/
├─ index.html # 支付页主文件
├─ template.json # 主题基础描述
└─ assets/ # 静态资源目录(可被外部访问)
├─ js/ # JavaScript 资源
├─ css/ # 样式资源
├─ images/ # 图片资源
└─ font/ # 字体资源[主题名称]:自定义主题文件夹名称,便于多主题管理。index.html:支付页模板主入口文件。template.json:主题基础信息。assets/:所有静态资源均应放置于此,避免主目录暴露敏感文件。template.json 结构如下
{
"name": "现代浮窗风格支付模板",
"version": "1.0.0",
"description": "现代浮窗风格支付模板",
"author": "XArrPay",
"license": "MIT",
"screenshot": "screenshot.png" # 主题缩略图
}
${.templateAssets} 作为资源路径前缀,确保路径正确、主题切换无影响。${.templateAssets}:自动指向当前主题的 assets 目录。${.templateAssets} 变量拼接,禁止硬编码绝对路径。${ }include 引入公共片段,如 header/footer:go 语言符号${"string"} // 一般 string
${`raw string`} // 原始 string
${'c'} // byte
${print nil} // nil 也被支持pipeline${. | FuncA | FuncB | FuncC}pipeline 的值等于:false 或 0nil的指针 或 interface0 的 array, slice, map, stringpipeline 被认为是空。<no value>)。if … else … end${if pipeline}...${end}if 判断时, pipeline 为空时,相当于判断为 false。${if .condition}
...
${else}
${if .condition2}
...
${end}
${end}else if 进行${if .condition}
...
${else if .condition2}
...
${else}
...
${end}range … end${range pipeline} ${.} ${end}pipeline 支持的类型为 slice, map, channel。0 时, range 不会执行, . 不会改变。map:${range $key, $value := .MapContent}
${$key}:${$value}
${end}slice:${range $index, $elem := .SliceContent}
${range $key, $value := $elem}
${$key}:${$value}
${end}
${end}with … end${with pipeline}...${end}with 用于重定向 pipeline${with .Field.NestField.SubField}
${.Var}
${end}definedefine 可以用来 自定义模板内容块(给一段模板内容定义一个模板名称),可用于模块定义和模板嵌套(使用在 template 标签中)。${define "loop"}
<li>${.Name}</li>
${end}loop 为该模板内容块的名称,随后可使用 template 标签调用模板:<ul>
${range .Items}
${template "loop" .}
${end}
</ul>define 标签需要结合 template 标签一起使用,并且支持跨模板使用(在同一模板目录/子目录下有效,原理是使用的 ParseFiles 方法解析模板文件)。template${template "模板名称" pipeline}pipeline 传给模板,才可以在模板中调用。template 标签参数为 模板名称,而不是模板文件路径, template 标签不支持模板文件路径。template 标签需要结合 define 标签一起使用,并且支持跨模板使用(在同一模板目录/子目录下有效,原理是使用的 ParseFiles 方法解析模板文件)。include${include "模板文件名(需要带完整文件名后缀)" pipeline}include 标签载入其他模板(任意路径),模板文件名支持 相对路径 以及文件的系统 绝对路径。如果想要把当前模板的模板变量传递给子模板(嵌套模板),可以这样:${include "模板文件名(需要带完整文件名后缀)" .}template 标签的区别是: include 仅支持 文件路径,不支持 模板名称;而 tempalte 标签仅支持 模板名称,不支持 文件路径。${/*
comment content
support new line
*/}# 使 用${-语法去除模板内容左侧的所有空白符号, 使用-}去除模板内容右侧的所有空白符号。
# 注意:-要紧挨${和},同时与模板值之间需要使用空格分隔。
${- .Name -}
${- range $key, $value := .list}
"${$value}"
${- end}layouts/
├─ layout.html
├─ header.html
├─ footer.html
└─ container.htmllayout.htmlheader.htmlcontainer.htmlfooter.htmlinclude 模板嵌入include 标签来实现页面布局。${include "xxx" .} 的语法。layout.htmlheader.htmlfooter.htmlmain1.htmlmain2.html