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

package gview

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

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

Reserved template variable names:

I18nLanguage: Assign this variable to define i18n language for each page.

Index

Package Files

gview.go gview_buildin.go gview_config.go gview_error.go gview_i18n.go gview_instance.go gview_parse.go

Constants

const (
    // Default group name for instance usage.
    DEFAULT_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 Config Uses

type Config struct {
    Paths       []string               // Searching array for path, NOT concurrent-safe for performance purpose.
    Data        map[string]interface{} // Global template variables including configuration.
    DefaultFile string                 // Default template file for parsing.
    Delimiters  []string               // Custom template delimiters.
    AutoEncode  bool                   // Automatically encodes and provides safe html output, which is good for avoiding XSS.
    I18nManager *gi18n.Manager         // I18n manager for the view.
}

Config is the configuration object for template engine.

func DefaultConfig Uses

func DefaultConfig() Config

DefaultConfig creates and returns a configuration object with default configurations.

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 global template variable to current view object. Note that it's not concurrent-safe, which means it would panic if it's called in multiple goroutines in runtime.

func (*View) Assigns Uses

func (view *View) Assigns(data Params)

Assigns binds multiple global template variables to current view object. Note that it's not concurrent-safe, which means it would panic if it's called in multiple goroutines in runtime.

func (*View) BindFunc Uses

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

BindFunc registers customized global 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 global 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) GetDefaultFile Uses

func (view *View) GetDefaultFile() string

GetDefaultFile returns default template file for parsing.

func (*View) Parse Uses

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

Parse parses given template file <file> with given template variables <params> and returns the parsed template content.

func (*View) ParseContent Uses

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

ParseContent parses given template content <content> with template variables <params> and returns the parsed content in []byte.

func (*View) ParseDefault Uses

func (view *View) ParseDefault(params ...Params) (result string, err error)

ParseDefault parses the default template file with params.

func (*View) SetAutoEncode Uses

func (view *View) SetAutoEncode(enable bool)

SetAutoEncode enables/disables automatically html encoding feature. When AutoEncode feature is enables, view engine automatically encodes and provides safe html output, which is good for avoid XSS.

func (*View) SetConfig Uses

func (view *View) SetConfig(config Config) error

SetConfig sets the configuration for view.

func (*View) SetConfigWithMap Uses

func (view *View) SetConfigWithMap(m map[string]interface{}) error

SetConfigWithMap set configurations with map for the view.

func (*View) SetDefaultFile Uses

func (view *View) SetDefaultFile(file string)

SetDefaultFile sets default template file for parsing.

func (*View) SetDelimiters Uses

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

SetDelimiters sets customized delimiters for template parsing.

func (*View) SetI18n Uses

func (view *View) SetI18n(manager *gi18n.Manager)

SetI18n binds i18n manager to current view engine.

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 26 packages (graph) and is imported by 4 packages. Updated 2020-07-18. Refresh now. Tools for package owners.