支持相对路径的模板引擎 Go template

码农软件 · 软件分类 · 模板引擎 · 2019-08-23 16:56:44

软件介绍

基于官方 text/template 和 html/template 的模板引擎. Template 通过几种惯用方式组合, 为模板提供简洁的使用方式.

特性:
  • 模板名仿效 URI 格式, 使用全路径名称命名.

  • 模板名以 ".html" 结尾当作 HTML 模板处理, 否则当作 TEXT 模板处理.

  • 模板源码可使用相对路径名指示目标模板.

  • 引入 RootDir 限制模板文件根目录.

  • 内置 import 函数支持变量名表示模板名.

示例模板:

<html>
<head>
<meta charset="UTF-8">
{{import .js}}
</head>
<body>
{{import .body .}}
</body>
{{template "foot.html"}}
</html>

示例代码:

package main

import (
    "github.com/achun/template"
    "os"
)

var data = map[string]interface{}{
    "title": `>title`,
    "body":  `/admin/body.html`,
    "js":    `/admin/js.tmpl`,
    "href":  ">>>",
    "name":  "admin",
}

func main() {
    pwd, _ := os.Getwd()
    t, err := template.New("./fixtures/base/layout.html")
    t.Walk(pwd+`/fixtures/base`, ".html.tmpl")
    t.Execute(os.Stdout, data)
}

本文地址:https://codercto.com/soft/d/13008.html

The Dream Machine

The Dream Machine

M. Mitchell Waldrop / Penguin Books / 2002-8 / USD 16.00

While most people may not be familiar with the name J. C. R. Licklider, he was the guiding spirit behind the greatest revolution of the modern era. At a time when most computers were big, ponderous ma......一起来看看 《The Dream Machine》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具