Plet is a simple template package for web apps. Plet wraps html/template
and provides helper functions.
Layout: layout templates serves as base for content templates.
Content: content templates is where you define the sections of your templates.
tmplt/layout/basic/basic.html: layout template. Note that for layout templates, folder name must match the template declaration.
{{ define "basic" }}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{ template "head" . }}
</head>
<body>
{{ template "content" . }}
{{ template "foot" . }}
</body>
</html>
{{ end }}
tmplt/content/simple/head.html
{{ define "head" }}
<title>Plet | Template Management Package</title>
{{ end }}
tmplt/content/simple/content.html
{{ define "content" }}
<h1>Hello World!</h1>
{{ end }}
tmplt/content/simple/foot.html
{{ define "foot" }}
<p>Hello, I'm a footer!</p>
{{end}}
import (
"log"
"os"
"github.com/steven-ferrer/plet"
)
const (
contentDir = "tmplt/content/"
layoutDir = "tmplt/layout/"
)
//very simple example of using plet package
func main() {
//new template
t := plet.New(contentDir+"simple", layoutDir+"basic")
//initialize template, this will compile the template
err := t.Init()
if err != nil {
log.Fatal(err)
}
err = t.Execute(os.Stdout, nil)
if err != nil {
log.Fatal(err)
}
}
For more examples please see examples folder.
If you found a bug or have a question, please feel free to open an issue.
Please feel free to contribute by submitting a PR.