Skip to content
This repository has been archived by the owner on May 28, 2020. It is now read-only.

stevenferrer/plet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Report Card godocs

Plet

Plet is a simple template package for web apps. Plet wraps html/template and provides helper functions.

Terminologies

Layout: layout templates serves as base for content templates.

Content: content templates is where you define the sections of your templates.

Basic Usage

layout template

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 }}

content templates

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}}

basic.go:

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)
	}
}

More Examples

For more examples please see examples folder.

Issues and Question

If you found a bug or have a question, please feel free to open an issue.

Contributing

Please feel free to contribute by submitting a PR.

About

Plet is a template package for web apps that wraps html/template

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages