modulepackage
0.3.0
Repository: https://github.com/dvaumoron/partrenderer.git
Documentation: pkg.go.dev
# README
PartRenderer
Library to load several go template decomposed in multiple file and render them globally or partially (useful with htmx).
Getting started
In order to use PartRenderer in your project (with the go langage already installed), you can use the command :
go get github.com/dvaumoron/partrenderer@latest
Then you can import it :
import "github.com/dvaumoron/partrenderer"
And use it in two step :
// parse templates
renderer, err := partrenderer.MakePartRenderer(componentsPath, viewsPath)
// and use them
err = renderer.ExecuteTemplate(writer, viewName, data)
The first call with :
- componentsPath indicate a directory to walk in order to load all component templates
- viewsPath indicate a directory to walk in order to load all view templates (which can see components)
The second call has the same signature as Template.ExecuteTemplate where viewName has no extention ("hello/index" for an index.html file in hello folder) and can have a part selector (like in "hello/index#body", without this selector "root" is used).
With componentsPath/main.html like :
{{define "root"}}
<html>
<head>
<meta charset="utf-8"/>
{{template "header" .}}
</head>
<body>
{{template "body" .}}
</body>
</html>
{{end}}
And viewsPath/hello/index.html like :
{{define "header"}}
<title>Hello World</title>
{{end}}
{{define "body"}}
<h1 class="greetings">Hello World</h1>
{{end}}
See advanced examples of componentsPath and viewsPath templates.
# Functions
No description provided by the author
The componentsPath argument indicates a directory to walk in order to load all component templates
The viewsPath argument indicates a directory to walk in order to load all view templates (which can see components).
No description provided by the author
No description provided by the author
option to use an alternate extension to filter loaded file (default is ".html").
option to use an alternate file system.
allow to load a template.FuncMap before parsing the go templates.
option to change the rule to reload on error (default is ReloadOnViewNotFound).
# Variables
No description provided by the author
# Structs
No description provided by the author