tmpl

package
v2.5.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package tmpl wraps a lot of html/template for easier use with common layout setup and sub-templates

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FuncMap

type FuncMap template.FuncMap

FuncMap aliases the html/template FuncMap for easier local use

type TRoot

type TRoot struct {
	Path string
	// contains filtered or unexported fields
}

TRoot wraps template.Template for use to spawn "real" templates. The TRoot is never meant to be directly rendered itself, but a top-level object for collecting the template path on disk, a layout template and shared templates (e.g., sidebar), and template functions for reuse in renderable templates

func Root

func Root(name, path string) *TRoot

Root creates a new TRoot for use in spawning templates. The name should match the main layout's name (as defined in the layout template) so execution of templates doesn't require a template.Lookup call, which can be somewhat error prone.

func (*TRoot) Build

func (t *TRoot) Build(path string) (*Template, error)

Build clones the root (for layout, funcs, etc) and parses the given file in the clone. The returned template is the clone, and is safe to alter without worrying about breaking the root.

func (*TRoot) Clone

func (t *TRoot) Clone() *TRoot

Clone creates a copy of the TRoot for ease of creating sub-layouts. Since TRoots cannot be executed externally, we don't have the possibility of returning an error.

func (*TRoot) Funcs

func (t *TRoot) Funcs(fnList FuncMap) *TRoot

Funcs allows adding template function maps to TRoots; this should be done before creating any templates, or else previously created templates won't get the newest function maps

func (*TRoot) MustBuild

func (t *TRoot) MustBuild(path string) *Template

MustBuild calls Build and panics on any error

func (*TRoot) MustReadPartials

func (t *TRoot) MustReadPartials(files ...string)

MustReadPartials calls ReadPartials and panics on any error

func (*TRoot) Name

func (t *TRoot) Name() string

Name exposes the underlying template's name

func (*TRoot) ReadPartials

func (t *TRoot) ReadPartials(files ...string) error

ReadPartials parses the given files into the TRoot instance for gathering things like the top-level layout, navigation elements, etc. The list of files is relative to the TRoot's Path. Returns on the first error encountered, if any.

type Template

type Template struct {
	*template.Template
	Name string
}

Template wraps html/template's type in order to provide a name so a single template can be self-contained

func (*Template) Clone

func (t *Template) Clone() (*Template, error)

Clone wraps html/template.Clone to also clone the name

Jump to

Keyboard shortcuts

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