template_engine

package
v2.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func A

func A(text string, urlStr string, options ...map[string]any) string

A 生成HTML超链接标签 text: 链接显示的文本 urlStr: 链接地址 options: 可选参数,可以包含HTML属性如class, id等

func ASafe

func ASafe(text, urlStr string, options ...map[string]any) string

func AWithQuery

func AWithQuery(text string, baseUrl string, queryParams map[string]any, options ...map[string]any) string

AWithQuery text: 链接显示的文本 baseUrl: 基础URL queryParams: 查询参数 options: 可选HTML属性

func Dict

func Dict(values ...any) map[string]any

Dict 创建一个map,用于模板中传递多个键值对 只返回一个值,如果参数错误返回空map

func LoopInt

func LoopInt(start, end int) []int

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func New

func New(fsys fs.FS, fsysPath, localPath string, devMode bool) *Engine

New 创建模板引擎实例 fsys: 生产模式使用的 embed.FS fsysPath: 生产模式下的虚拟路径 localPath: 开发模式下的本地模板目录路径 devMode: 是否为开发模式

func (*Engine) AddFunc

func (e *Engine) AddFunc(name string, fn any)

AddFunc 添加自定义函数

func (*Engine) Load

func (e *Engine) Load() error

func (*Engine) Render

func (e *Engine) Render(w io.Writer, name string, data any) error

Render 渲染模板到 io.Writer

func (*Engine) RenderString

func (e *Engine) RenderString(name string, data any) (string, error)

RenderString 渲染模板为字符串

func (*Engine) SetExts

func (e *Engine) SetExts(exts ...TplExt)

func (*Engine) SetLayoutDir

func (e *Engine) SetLayoutDir(dir string)

SetLayoutDir 设置layout目录名称(如"layouts")

type TplExt

type TplExt string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL