Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseFS ¶ added in v0.5.0
ParseFS creates a new text/Template and parses the template definitions from the files identified by the pattern. The files are matched according to the semantics of filepath.Match, and the pattern must match at least one file. The returned template will have the (base) name and (parsed) contents of the first file matched by the pattern.
func ParseWith ¶ added in v0.5.1
ParseWith like ParseFS but need provide a *template.Template instance as parameter.
Example ¶
embedFS := ChangeRoot(content, "html/testdata") funcTmpl := template.New("embedx").Funcs(template.FuncMap{ "notEmptyStr": notEmptyStr, }) tmpl, err := ParseWith(funcTmpl, embedFS, "templates/*.tmpl", "templates/b/*.tmpl", "templates/d/*.tmpl") if err != nil { log.Fatal(err) } for _, ctx := range []struct { Name string }{ {"templates/a.tmpl"}, {"templates/b/c.tmpl"}, {"templates/d/e.tmpl"}, {"templates/d/f.tmpl"}, } { bs := &bytes.Buffer{} if err = tmpl.ExecuteTemplate(bs, ctx.Name, ctx); err != nil { log.Fatal(err) } fmt.Println(bs) }
Output:
func RegisterNamer ¶ added in v0.6.0
func RegisterNamer(n Namer)
RegisterNamer register a new namer replace default. Note: this function is not concurrent safe.
Types ¶
type EmbedFS ¶ added in v0.3.0
type EmbedFS interface { fs.FS ReadDir(name string) ([]fs.DirEntry, error) ReadFile(name string) ([]byte, error) }
EmbedFS embed.FS public method re-defined as interface
func AttachRoot ¶ added in v0.2.0
AttachRoot attach to a virtual root directory like mount to a new directory.
func ChangeRoot ¶ added in v0.2.0
ChangeRoot change to a new directory like cd cmd in shell but not check whether this directory is exist.