gf: github.com/gogf/gf/g/os/gview Index | Files

package gview

import "github.com/gogf/gf/g/os/gview"

Package gview implements a template engine based on text/template.

Index

Package Files

gview.go gview_buildin.go gview_config.go gview_doparse.go gview_error.go gview_instance.go

Constants

const (
    // Default group name for instance usage.
    DEFAULT_INSTANCE_NAME = "default"
)

func ParseContent Uses

func ParseContent(content string, params Params) (string, error)

ParseContent parses the template content directly using the default view object and returns the parsed content.

type FuncMap Uses

type FuncMap = map[string]interface{}

FuncMap is type for custom template functions.

type Params Uses

type Params = map[string]interface{}

Params is type for template params.

type View Uses

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

View object for template engine.

func Instance Uses

func Instance(name ...string) *View

Instance returns an instance of View with default settings. The parameter <name> is the name for the instance.

func New Uses

func New(path ...string) *View

New returns a new view object. The parameter <path> specifies the template directory path to load template files.

func (*View) AddPath Uses

func (view *View) AddPath(path string) error

AddPath adds a absolute or relative path to the search paths.

func (*View) Assign Uses

func (view *View) Assign(key string, value interface{})

Assign binds a template variable to current view object. Each goroutine will take effect after the call, so it is concurrent-safe.

func (*View) Assigns Uses

func (view *View) Assigns(data Params)

Assign binds multiple template variables to current view object. Each goroutine will take effect after the call, so it is concurrent-safe.

func (*View) BindFunc Uses

func (view *View) BindFunc(name string, function interface{})

BindFunc registers customized template function named <name> with given function <function> to current view object. The <name> is the function name which can be called in template content.

func (*View) BindFuncMap Uses

func (view *View) BindFuncMap(funcMap FuncMap)

BindFuncMap registers customized template functions by map to current view object. The key of map is the template function name and the value of map is the address of customized function.

func (*View) Parse Uses

func (view *View) Parse(file string, params ...Params) (parsed string, err error)

ParseContent parses given template file <file> with given template parameters <params> and function map <funcMap> and returns the parsed string content.

func (*View) ParseContent Uses

func (view *View) ParseContent(content string, params ...Params) (string, error)

ParseContent parses given template content <content> with given template parameters <params> and function map <funcMap> and returns the parsed content in []byte.

func (*View) SetDelimiters Uses

func (view *View) SetDelimiters(left, right string)

SetDelimiters sets customized delimiters for template parsing.

func (*View) SetPath Uses

func (view *View) SetPath(path string) error

SetPath sets the template directory path for template file search. The parameter <path> can be absolute or relative path, but absolute path is suggested.

Package gview imports 22 packages (graph) and is imported by 8 packages. Updated 2019-06-19. Refresh now. Tools for package owners.