view

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HtmlRender

func HtmlRender(tplPath string, viewData interface{}, includeFiles ...string) (res string)

func ParseViewName

func ParseViewName(viewName string) string

func SetTemplatePath

func SetTemplatePath(path string)

func TextRender

func TextRender(tplPath string, viewData interface{}, includeFiles ...string) (res string)

Types

type DefaultEngine

type DefaultEngine struct {
	TemplatePath string
	// contains filtered or unexported fields
}

func NewDefaultViewEngine

func NewDefaultViewEngine() *DefaultEngine

func (*DefaultEngine) AddIncludeTmpl

func (c *DefaultEngine) AddIncludeTmpl(viewName string)

添加引入模版

func (*DefaultEngine) SetTemplatePath

func (c *DefaultEngine) SetTemplatePath(option *Option)

func (*DefaultEngine) ShareViewData

func (c *DefaultEngine) ShareViewData(key string, viewData interface{})

全局通用模板变量

func (*DefaultEngine) ViewHtml

func (c *DefaultEngine) ViewHtml(viewName string, viewDataset ...interface{}) (string, error)

ViewHtml 快速渲染html视图

type IViewEngine

type IViewEngine interface {
	ViewHtml(viewName string, viewDataset ...interface{}) (string, error)
	AddIncludeTmpl(viewName string)
	SetTemplatePath(option *Option)
}

func CreateViewEngine

func CreateViewEngine() IViewEngine

type Option

type Option struct {
	Path     string   `mapstructure:"path"`
	Includes []string `mapstructure:"includes"`
}

type Template

type Template struct {
	ViewName    string
	ViewPath    string
	IncludeTmpl []string
	ShowData    map[string]interface{}
	// contains filtered or unexported fields
}

func New

func New(viewName string, includeFiles ...string) *Template

func (*Template) Render

func (t *Template) Render() (viewHtmlRes string, err error)

func (*Template) RenderText

func (t *Template) RenderText() (viewHtmlRes string, err error)

func (*Template) ViewData

func (t *Template) ViewData(values interface{}) *Template

view data is map[string]interface{}

func (*Template) ViewDataKV

func (t *Template) ViewDataKV(name string, value interface{}) *Template

view data is name and value , that value is interface{}

Jump to

Keyboard shortcuts

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