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:
10
view/html.go
10
view/html.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user