gview

package
v0.0.0-...-3e416e1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: MIT Imports: 5 Imported by: 1

README

GMC VIEW

gmc view module, make it very easy to render your template.

CONFIGURATION

about template configuration is section [template] in app.toml.

[template]
dir="views"
ext=".html"
delimiterleft="{{"
delimiterright="}}"

FUNCTIONS

text/template inside functions

and, call, html, index, slice, js, len, not, or, print, printf, println, urlquery

text/template inside comparison functions

eq, ne, lt, le, gt, ge

gmc defined functions
  1. tr be used in i18n, first argument is always .Lang, secondary is key name in your i18n locale config file. third is optional tips text for yourself , it will be not output. returns template.HTML typed string.

    Example in the template:

    {{tr .Lang "key001" "tips"}}

  2. trs as same as tr, but returns string type.

  3. string only one argument, type is interface{}, convert it to string type.

  4. tohtml only one argument, convert it to template.HTML type.

  5. val get template variable value, if variable not exits it returns "" instead of .

gmc defined comparison functions
gmc defined variables
  1. .Lang is the i18n standard FLAG the result of parsed client browser's Accept-Language HTTP header.
    It is be used in the i18n tr function.

  2. .G access GET data from URL query string. .G is a map[string][string], .G.key key is query name in query string.

  3. .P access POST form data. .P is a map[string][string], .P.key key is form field name in POST form.

  4. .S access session data from the current session. .S is a map[string][string], .S.key key is query name in query string.
    Notice that this only worked after the SessionStart() in a controller is be called.

  5. .C access COOKIE data. .C is a map[string][string], .C.key key is cookie field name in cookies raw string.

  6. .U current URL information u:=map[string]string.

  7. .H request HTTP HEADER information h:=map[string]string.

    u["HOST"] = u0.Host
    u["HOSTNAME"]=u0.Hostname()
    u["PORT"]=u0.Port()
    u["PATH"] = u0.Path
    u["FRAGMENT"] = u0.Fragment
    u["OPAQUE"] = u0.Opaque
    u["RAW_PATH"] = u0.RawPath
    u["RAW_QUERY"] = u0.RawQuery
    u["SCHEME"] = u0.Scheme
    u["USER"] = u0.User.Username()
    u["PASSWORD"],_ = u0.User.Password()
    u["URI"]=u0.RequestURI()
    u["URL"]=u0.String()
    

    TIPS: [scheme:][//[userinfo@]host][/]path[?query][#fragment]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(w io.Writer, tpl gcore.Template) gcore.View

Types

type View

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

func (*View) Err

func (this *View) Err() error

func (*View) Layout

func (this *View) Layout(l string) gcore.View

Layout sets the views layout when render template.

func (*View) OnRenderOnce

func (this *View) OnRenderOnce(f func()) gcore.View

OnRenderOnce injects GPSC data

func (*View) Render

func (this *View) Render(tpl string, data ...map[string]interface{}) gcore.View

Render renders template `tpl` with `data`, and output.

func (*View) RenderR

func (this *View) RenderR(tpl string, data ...map[string]interface{}) (d []byte)

RenderR renders template `tpl` with `data`, and returns render result.

func (*View) Set

func (this *View) Set(key string, val interface{}) gcore.View

Set sets data apply to the template

func (*View) SetLayoutDir

func (this *View) SetLayoutDir(layoutDir string)

SetLayoutDir sets default dir of layout

func (*View) SetMap

func (this *View) SetMap(d map[string]interface{}) gcore.View

SetMap sets mapped data apply to the template

func (*View) Stop

func (this *View) Stop()

Stop exit controller method

Jump to

Keyboard shortcuts

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