templates

package
v0.0.0-...-774a802 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

A Collection is a set of pages that share a base layout, partials, and template funcs

func NewCollection

func NewCollection(filesystem fs.FS, funcMap template.FuncMap) (Collection, error)

NewCollection takes a fs.FS containing the template sources. The filesystem is expected to be in the following format:

templates/
├─ pages/
│  ├─ page1.gohtml
│  ├─ page2.gohtml
├─ partials/
│  ├─ nav.gohtml
│  ├─ footer.gohtml
├─ base.gohtml

base.gohtml is a required filename and defines the top-level template. It refers to content blocks defined by the partials and pages. The filenames for the partials don't matter, only the names of the templates they define. The pages are referred by their filename in the Render method.

func (Collection) Render

func (tc Collection) Render(w io.Writer, page string, data any) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL