1
0
mirror of https://github.com/kataras/iris.git synced 2026-03-08 01:16:30 +00:00

view: allow only-custom template parsing

This commit is contained in:
Gerasimos (Makis) Maropoulos
2023-03-13 14:39:11 +02:00
parent c9c13d76b5
commit 7672574232
4 changed files with 28 additions and 1 deletions

View File

@@ -10,6 +10,8 @@ import (
"path/filepath"
"strings"
"sync"
"github.com/kataras/iris/v12/context"
)
// HTMLEngine contains the html view engine structure.
@@ -61,7 +63,8 @@ var (
// Usage:
// HTML("./views", ".html") or
// HTML(iris.Dir("./views"), ".html") or
// HTML(embed.FS, ".html") or HTML(AssetFile(), ".html") for embedded data.
// HTML(embed.FS, ".html") or HTML(AssetFile(), ".html") for embedded data or
// HTML("","").ParseTemplate("hello", `[]byte("hello {{.Name}}")`, nil) for custom template parsing only.
func HTML(dirOrFS interface{}, extension string) *HTMLEngine {
s := &HTMLEngine{
name: "HTML",
@@ -243,6 +246,11 @@ func (s *HTMLEngine) load() error {
return err
}
// If only custom templates should be loaded.
if (s.fs == nil || context.IsNoOpFS(s.fs)) && len(s.Templates.DefinedTemplates()) > 0 {
return nil
}
rootDirName := getRootDirName(s.fs)
err := walk(s.fs, "", func(path string, info os.FileInfo, err error) error {