render

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllHelpers = hctx.Merge(
	content.New(),
	debug.New(),
	encoders.New(),
	env.New(),
	escapes.New(),
	iterators.New(),
	meta.New(),
	text.New(),
)

AllHelpers contains all of the default helpers for These will be available to all templates.

View Source
var InCtx = Middleware

InCtx puts the render engine in the context so the handlers can use it, it also sets a few other values that are useful for the handlers.

Functions

func Middleware

func Middleware(templates fs.FS, options ...Option) func(http.Handler) http.Handler

Middleware puts the render engine in the context so the handlers can use it, it also sets a few other values that are useful for the handlers.

func TemplateFS added in v1.2.13

func TemplateFS(embed fs.FS, dir string) templatesFS

NewFallbackFS returns a new FS that wraps the given directory and embedded FS. the embed.FS is expected to embed the same files as the directory FS.

Types

type Engine

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

func EngineFromCtx added in v1.2.12

func EngineFromCtx(ctx context.Context) *Engine

FromCtx returns the render engine from the context, it assumes the render render engine has been set by the render middleware.

func NewEngine

func NewEngine(fs fs.FS, options ...Option) *Engine

NewEngine builds the render engine based on the file system and the options passed to it.

func (*Engine) HTML

func (e *Engine) HTML(w io.Writer) *Page

func (*Engine) RenderHTML added in v1.2.12

func (e *Engine) RenderHTML(template string, values map[string]any) (string, error)

func (*Engine) Set

func (e *Engine) Set(key string, value any)

func (*Engine) SetHelper

func (e *Engine) SetHelper(key string, value any)

type Option

type Option func(*Engine)

func WithDefaultLayout

func WithDefaultLayout(layout string) Option

WithDefaultLayout sets the default layout for the engine if no layout is specified in the template this layout will be used. By default this is set to "app/layouts/application.html"

func WithHelpers

func WithHelpers(hps map[string]any) Option

WithHelpers sets the helpers for the engine these helpers will be available in all templates rendered by this engine.

type Page

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

func FromCtx

func FromCtx(ctx context.Context) *Page

FromCtx returns the render engine from the context when its called it also adds any value in the valuer into the page, this is useful for the middlewares such as session to add values to the page.

func (*Page) Render

func (p *Page) Render(page string) error

func (*Page) RenderClean

func (p *Page) RenderClean(name string) error

func (*Page) RenderWithLayout

func (p *Page) RenderWithLayout(page, layout string) error

func (*Page) Set

func (p *Page) Set(key string, value any)

func (*Page) Value

func (p *Page) Value(key string) any

Jump to

Keyboard shortcuts

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