Help us shape the future of Go! Take the 2026 Go Developer Survey

view

package
v1.20.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(options CompileOptions) (*template.Template, error)

Compile parses the application's resources/views directory and every package source in options into one template set, in precedence order: application views first, then options.Paths, then options.FS, each in the order given.

Every file is parsed under its slash-separated path relative to its source root, and additionally under the name of its {{ define }} block when it has one. A name already taken by a higher-precedence source causes the whole file to be skipped: silently when the application owns the name, with a warning when another package does. Route drivers wrap the returned set in their own renderer type.

Compile returns (nil, nil) when no source contributed a file.

Types

type CompileOptions

type CompileOptions struct {
	// Delims replaces the default "{{" and "}}" action delimiters.
	Delims *Delims
	// FuncMap is installed on the template set before any file is parsed.
	FuncMap template.FuncMap
	// Paths are package view directories in precedence order, typically
	// View.RegisteredViews(). A path that is missing or not a directory is skipped.
	Paths []string
	// FS are package view filesystems in precedence order, typically
	// View.RegisteredViewFS(). A nil or unreadable filesystem is skipped with a warning.
	FS []fs.FS
	// Extensions limits parsing to files with one of these extensions, dot
	// included. Empty parses every file.
	Extensions []string
	// Log receives warnings about name collisions and skipped filesystems. nil
	// silences them.
	Log contractslog.Log
}

CompileOptions configures Compile.

type Delims

type Delims struct {
	Left  string
	Right string
}

Delims are custom template action delimiters.

type ServiceProvider

type ServiceProvider struct{}

func (*ServiceProvider) Boot

func (r *ServiceProvider) Boot(app foundation.Application)

func (*ServiceProvider) Register

func (r *ServiceProvider) Register(app foundation.Application)

func (*ServiceProvider) Relationship

func (r *ServiceProvider) Relationship() contractsbinding.Relationship

type Template

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

Template is a view bound to its data. Data that cannot be rendered, and a First that matched nothing, are reported by Render rather than when the template is built.

func (*Template) Data

func (r *Template) Data() map[string]any

Data returns a shallow copy of the data passed to the template, without the shared data.

func (*Template) Name

func (r *Template) Name() string

func (*Template) Render

func (r *Template) Render() (string, error)

func (*Template) With

func (r *Template) With(key string, value any) contractsview.Template

type View

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

func NewView

func NewView() *View

func (*View) AddFuncs

func (r *View) AddFuncs(funcs template.FuncMap)

AddFuncs merges funcs into the registry. A later registration overrides an earlier one with the same name, so the application's functions, which the framework adds after every provider has booted, win over package functions.

func (*View) Exists

func (r *View) Exists(view string) bool

Exists reports whether a view file with the given name is available from any source. Only files count: directories, "" and "." (which would resolve to a source root) do not match.

func (*View) First

func (r *View) First(views []string, data ...any) contractsview.Template

First returns a template for the first view in the list that can be rendered.

func (*View) Funcs

func (r *View) Funcs() template.FuncMap

Funcs returns a copy of the registered functions, so callers may hand it to html/template.Funcs without affecting later registrations.

func (*View) GetShared

func (r *View) GetShared() map[string]any

func (*View) LoadViewsFrom

func (r *View) LoadViewsFrom(path string)

func (*View) LoadViewsFromFS

func (r *View) LoadViewsFromFS(fsys fs.FS, root string)

func (*View) Make

func (r *View) Make(view string, data ...any) contractsview.Template

Make returns a template for the view, bound to the given data.

func (*View) RegisteredViewFS

func (r *View) RegisteredViewFS() []fs.FS

func (*View) RegisteredViews

func (r *View) RegisteredViews() []string

func (*View) Share

func (r *View) Share(key string, value any)

func (*View) Shared

func (r *View) Shared(key string, def ...any) any

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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