Skip to content

yohcop/ntemplate.go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Implements nested templates in Go.
Uses the template package, but allows for nested templates.

Install:
goinstall github.com/yohcop/ntemplate.go/ntemplate


Example of use:
  import "github.com/yohcop/ntemplate.go/ntemplate"
  // ...

  // Create a configuration, specifies the base dir, and if the templates
  // files should be cached.
  conf := &Config{Basedir: "testdata", Cache: false}

  // Create a template that will be nested
  nested := conf.Template("nested.tpl")
  // And set some values.
  nested.Vars["var1"] = []string{"Nested", "Simple", "Useful"}

  // Create the parent template
  a := conf.Template("main.tpl")
  // Add the nested template, and some more values.
  a.Vars["child"] = nested
  a.Vars["s1"] = "Hello"
  a.Vars["s2"] = "Thanks, Bye!"

  // Finally, render the template.
  s, _ := a.Render()


nested.tpl:
They are:
{.repeated section var1}
- {@},
{.end}

main.tpl:
{s1} Nested Templates,
{child}
{s2}

Expected output:
Hello Nested Templates,
They are:
- Nested,
- Simple,
- Useful,
Thanks, Bye!


Known issues:
It seems that some new lines are inserted after the template variables. Will investigate.

About

Nested templates in go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages