HTML creates and returns a new html view engine. The html engine used like the "html/template" standard go package but with a lot of extra features. The given "extension" MUST begin with a dot. Usage: HTML("./views", ".html") or HTML(iris.Dir("./views"), ".html") or HTML(embed.FS, ".html") or HTML(
(dirOrFS interface{}, extension string)
| 66 | // HTML(embed.FS, ".html") or HTML(AssetFile(), ".html") for embedded data or |
| 67 | // HTML("","").ParseTemplate("hello", `[]byte("hello {{.Name}}")`, nil) for custom template parsing only. |
| 68 | func HTML(dirOrFS interface{}, extension string) *HTMLEngine { |
| 69 | s := &HTMLEngine{ |
| 70 | name: "HTML", |
| 71 | fs: getFS(dirOrFS), |
| 72 | rootDir: "/", |
| 73 | extension: extension, |
| 74 | reload: false, |
| 75 | left: "{{", |
| 76 | right: "}}", |
| 77 | layout: "", |
| 78 | layoutFuncs: template.FuncMap{ |
| 79 | "yield": func(binding interface{}) template.HTML { |
| 80 | return template.HTML("") |
| 81 | }, |
| 82 | }, |
| 83 | funcs: make(template.FuncMap), |
| 84 | bufPool: &sync.Pool{New: func() interface{} { |
| 85 | return new(bytes.Buffer) |
| 86 | }}, |
| 87 | } |
| 88 | |
| 89 | return s |
| 90 | } |
| 91 | |
| 92 | // RootDir sets the directory to be used as a starting point |
| 93 | // to load templates from the provided file system. |