iris: github.com/kataras/iris/view Index | Files

package view

import "github.com/kataras/iris/view"

Index

Package Files

amber.go django.go engine.go funcs.go handlebars.go html.go jet.go pug.go view.go

Constants

const JetRuntimeVarsContextKey = "iris.jetvarmap"

JetRuntimeVarsContextKey is the Iris Context key to keep any custom jet runtime variables. See `AddJetRuntimeVars` package-level function and `JetEngine.AddRuntimeVars` method.

const NoLayout = "iris.nolayout"

NoLayout disables the configuration's layout for a specific execution.

Variables

var AsSafeValue = pongo2.AsSafeValue

AsSafeValue works like AsValue, but does not apply the 'escape' filter. Shortcut for `pongo2.AsSafeValue`.

var AsValue = pongo2.AsValue

AsValue converts any given value to a pongo2.Value Usually being used within own functions passed to a template through a Context or within filter functions.

Example:

AsValue("my string")

Shortcut for `pongo2.AsValue`.

func AddJetRuntimeVars Uses

func AddJetRuntimeVars(ctx context.Context, jetVarMap JetRuntimeVars)

AddJetRuntimeVars sets or inserts runtime jet variables through the Iris Context. This gives the ability to add runtime variables from different handlers in the request chain, something that the jet template parser does not offer at all.

Usage: view.AddJetRuntimeVars(ctx, view.JetRuntimeVars{...}). See `JetEngine.AddRuntimeVars` too.

type AmberEngine Uses

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

AmberEngine contains the amber view engine structure.

func Amber Uses

func Amber(directory, extension string) *AmberEngine

Amber creates and returns a new amber view engine.

func (*AmberEngine) AddFunc Uses

func (s *AmberEngine) AddFunc(funcName string, funcBody interface{})

AddFunc adds the function to the template's function map. It is legal to overwrite elements of the default actions: - url func(routeName string, args ...string) string - urlpath func(routeName string, args ...string) string - render func(fullPartialName string) (template.HTML, error).

func (*AmberEngine) Binary Uses

func (s *AmberEngine) Binary(assetFn func(name string) ([]byte, error), namesFn func() []string) *AmberEngine

Binary optionally, use it when template files are distributed inside the app executable (.go generated files).

The assetFn and namesFn can come from the go-bindata library.

func (*AmberEngine) ExecuteWriter Uses

func (s *AmberEngine) ExecuteWriter(w io.Writer, filename string, layout string, bindingData interface{}) error

ExecuteWriter executes a template and writes its result to the w writer. layout here is useless.

func (*AmberEngine) Ext Uses

func (s *AmberEngine) Ext() string

Ext returns the file extension which this view engine is responsible to render.

func (*AmberEngine) Load Uses

func (s *AmberEngine) Load() error

Load parses the templates to the engine. It is responsible to add the necessary global functions.

Returns an error if something bad happens, user is responsible to catch it.

func (*AmberEngine) Reload Uses

func (s *AmberEngine) Reload(developmentMode bool) *AmberEngine

Reload if set to true the templates are reloading on each render, use it when you're in development and you're boring of restarting the whole app when you edit a template file.

Note that if `true` is passed then only one `View -> ExecuteWriter` will be render each time, no concurrent access across clients, use it only on development status. It's good to be used side by side with the https://github.com/kataras/rizla reloader for go source files.

type DjangoEngine Uses

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

DjangoEngine contains the django view engine structure.

func Django Uses

func Django(directory, extension string) *DjangoEngine

Django creates and returns a new amber view engine.

func (*DjangoEngine) AddFilter Uses

func (s *DjangoEngine) AddFilter(filterName string, filterBody FilterFunction) *DjangoEngine

AddFilter registers a new filter. If there's already a filter with the same name, RegisterFilter will panic. You usually want to call this function in the filter's init() function: http://golang.org/doc/effective_go.html#init

Same as `RegisterFilter`.

func (*DjangoEngine) AddFunc Uses

func (s *DjangoEngine) AddFunc(funcName string, funcBody interface{})

AddFunc adds the function to the template's Globals. It is legal to overwrite elements of the default actions: - url func(routeName string, args ...string) string - urlpath func(routeName string, args ...string) string - render func(fullPartialName string) (template.HTML, error).

func (*DjangoEngine) Binary Uses

func (s *DjangoEngine) Binary(assetFn func(name string) ([]byte, error), namesFn func() []string) *DjangoEngine

Binary optionally, use it when template files are distributed inside the app executable (.go generated files).

The assetFn and namesFn can come from the go-bindata library.

func (*DjangoEngine) ExecuteWriter Uses

func (s *DjangoEngine) ExecuteWriter(w io.Writer, filename string, layout string, bindingData interface{}) error

ExecuteWriter executes a templates and write its results to the w writer layout here is useless.

func (*DjangoEngine) Ext Uses

func (s *DjangoEngine) Ext() string

Ext returns the file extension which this view engine is responsible to render.

func (*DjangoEngine) Load Uses

func (s *DjangoEngine) Load() error

Load parses the templates to the engine. It is responsible to add the necessary global functions.

Returns an error if something bad happens, user is responsible to catch it.

func (*DjangoEngine) RegisterFilter Uses

func (s *DjangoEngine) RegisterFilter(filterName string, filterBody FilterFunction) *DjangoEngine

RegisterFilter registers a new filter. If there's already a filter with the same name, RegisterFilter will panic. You usually want to call this function in the filter's init() function: http://golang.org/doc/effective_go.html#init

See http://www.florian-schlachter.de/post/pongo2/ for more about writing filters and tags.

func (*DjangoEngine) RegisterTag Uses

func (s *DjangoEngine) RegisterTag(tagName string, fn TagParser) error

RegisterTag registers a new tag. You usually want to call this function in the tag's init() function: http://golang.org/doc/effective_go.html#init

See http://www.florian-schlachter.de/post/pongo2/ for more about writing filters and tags.

func (*DjangoEngine) Reload Uses

func (s *DjangoEngine) Reload(developmentMode bool) *DjangoEngine

Reload if set to true the templates are reloading on each render, use it when you're in development and you're boring of restarting the whole app when you edit a template file.

Note that if `true` is passed then only one `View -> ExecuteWriter` will be render each time, no concurrent access across clients, use it only on development status. It's good to be used side by side with the https://github.com/kataras/rizla reloader for go source files.

type Engine Uses

type Engine interface {
    // Load should load the templates from a physical system directory or by an embedded one (assets/go-bindata).
    Load() error
    // ExecuteWriter should execute a template by its filename with an optional layout and bindingData.
    ExecuteWriter(w io.Writer, filename string, layout string, bindingData interface{}) error
    // Ext should return the final file extension which this view engine is responsible to render.
    Ext() string
}

Engine is the interface which all view engines should be implemented in order to be registered inside iris.

type EngineFuncer Uses

type EngineFuncer interface {
    // AddFunc should adds a function to the template's function map.
    AddFunc(funcName string, funcBody interface{})
}

EngineFuncer is an addition of a view engine, if a view engine implements that interface then iris can add some closed-relative iris functions like {{ urlpath }} and {{ urlpath }}.

type Error Uses

type Error = pongo2.Error

Error type alias for pongo2.Error

type FilterFunction Uses

type FilterFunction = pongo2.FilterFunction

FilterFunction type alias for pongo2.FilterFunction

type HTMLEngine Uses

type HTMLEngine struct {
    Templates *template.Template
    // contains filtered or unexported fields
}

HTMLEngine contains the html view engine structure.

func HTML Uses

func HTML(directory, extension string) *HTMLEngine

HTML creates and returns a new html view engine. The html engine used like the "html/template" standard go package but with a lot of extra features.

func Pug Uses

func Pug(directory, extension string) *HTMLEngine

Pug (or Jade) returns a new pug view engine. It shares the same exactly logic with the html view engine, it uses the same exactly configuration. It has got some features and a lot of functions which will make your life easier. Read more about the Jade Go Template: https://github.com/Joker/jade

Examples: https://github.com/kataras/iris/tree/master/_examples/view/template_pug_0 https://github.com/kataras/iris/tree/master/_examples/view/template_pug_1 https://github.com/kataras/iris/tree/master/_examples/view/template_pug_2 https://github.com/kataras/iris/tree/master/_examples/view/template_pug_3

func (*HTMLEngine) AddFunc Uses

func (s *HTMLEngine) AddFunc(funcName string, funcBody interface{})

AddFunc adds the function to the template's function map. It is legal to overwrite elements of the default actions: - url func(routeName string, args ...string) string - urlpath func(routeName string, args ...string) string - render func(fullPartialName string) (template.HTML, error).

func (*HTMLEngine) AddLayoutFunc Uses

func (s *HTMLEngine) AddLayoutFunc(funcName string, funcBody interface{}) *HTMLEngine

AddLayoutFunc adds the function to the template's layout-only function map. It is legal to overwrite elements of the default layout actions: - yield func() (template.HTML, error) - current func() (string, error) - partial func(partialName string) (template.HTML, error) - partial_r func(partialName string) (template.HTML, error) - render func(fullPartialName string) (template.HTML, error).

func (*HTMLEngine) Binary Uses

func (s *HTMLEngine) Binary(assetFn func(name string) ([]byte, error), namesFn func() []string) *HTMLEngine

Binary optionally, use it when template files are distributed inside the app executable (.go generated files).

The assetFn and namesFn can come from the go-bindata library.

func (*HTMLEngine) Delims Uses

func (s *HTMLEngine) Delims(left, right string) *HTMLEngine

Delims sets the action delimiters to the specified strings, to be used in templates. An empty delimiter stands for the corresponding default: {{ or }}.

func (*HTMLEngine) ExecuteWriter Uses

func (s *HTMLEngine) ExecuteWriter(w io.Writer, name string, layout string, bindingData interface{}) error

ExecuteWriter executes a template and writes its result to the w writer.

func (*HTMLEngine) Ext Uses

func (s *HTMLEngine) Ext() string

Ext returns the file extension which this view engine is responsible to render.

func (*HTMLEngine) Layout Uses

func (s *HTMLEngine) Layout(layoutFile string) *HTMLEngine

Layout sets the layout template file which inside should use the {{ yield }} func to yield the main template file and optionally {{partial/partial_r/render}} to render other template files like headers and footers

The 'tmplLayoutFile' is a relative path of the templates base directory, for the template file with its extension.

Example: HTML("./templates", ".html").Layout("layouts/mainLayout.html")

// mainLayout.html is inside: "./templates/layouts/".

Note: Layout can be changed for a specific call action with the option: "layout" on the iris' context.Render function.

func (*HTMLEngine) Load Uses

func (s *HTMLEngine) Load() error

Load parses the templates to the engine. It's also responsible to add the necessary global functions.

Returns an error if something bad happens, user is responsible to catch it.

func (*HTMLEngine) Option Uses

func (s *HTMLEngine) Option(opt ...string) *HTMLEngine

Option sets options for the template. Options are described by strings, either a simple string or "key=value". There can be at most one equals sign in an option string. If the option string is unrecognized or otherwise invalid, Option panics.

Known options:

missingkey: Control the behavior during execution if a map is indexed with a key that is not present in the map.

"missingkey=default" or "missingkey=invalid"
	The default behavior: Do nothing and continue execution.
	If printed, the result of the index operation is the string
	"<no value>".
"missingkey=zero"
	The operation returns the zero value for the map type's element.
"missingkey=error"
	Execution stops immediately with an error.

func (*HTMLEngine) Reload Uses

func (s *HTMLEngine) Reload(developmentMode bool) *HTMLEngine

Reload if set to true the templates are reloading on each render, use it when you're in development and you're boring of restarting the whole app when you edit a template file.

Note that if `true` is passed then only one `View -> ExecuteWriter` will be render each time, no concurrent access across clients, use it only on development status. It's good to be used side by side with the https://github.com/kataras/rizla reloader for go source files.

type HandlebarsEngine Uses

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

HandlebarsEngine contains the handlebars view engine structure.

func Handlebars Uses

func Handlebars(directory, extension string) *HandlebarsEngine

Handlebars creates and returns a new handlebars view engine.

func (*HandlebarsEngine) AddFunc Uses

func (s *HandlebarsEngine) AddFunc(funcName string, funcBody interface{})

AddFunc adds the function to the template's function map. It is legal to overwrite elements of the default actions: - url func(routeName string, args ...string) string - urlpath func(routeName string, args ...string) string - render func(fullPartialName string) (raymond.HTML, error).

func (*HandlebarsEngine) Binary Uses

func (s *HandlebarsEngine) Binary(assetFn func(name string) ([]byte, error), namesFn func() []string) *HandlebarsEngine

Binary optionally, use it when template files are distributed inside the app executable (.go generated files).

The assetFn and namesFn can come from the go-bindata library.

func (*HandlebarsEngine) ExecuteWriter Uses

func (s *HandlebarsEngine) ExecuteWriter(w io.Writer, filename string, layout string, bindingData interface{}) error

ExecuteWriter executes a template and writes its result to the w writer.

func (*HandlebarsEngine) Ext Uses

func (s *HandlebarsEngine) Ext() string

Ext returns the file extension which this view engine is responsible to render.

func (*HandlebarsEngine) Layout Uses

func (s *HandlebarsEngine) Layout(layoutFile string) *HandlebarsEngine

Layout sets the layout template file which should use the {{ yield }} func to yield the main template file and optionally {{partial/partial_r/render}} to render other template files like headers and footers.

func (*HandlebarsEngine) Load Uses

func (s *HandlebarsEngine) Load() error

Load parses the templates to the engine. It is responsible to add the necessary global functions.

Returns an error if something bad happens, user is responsible to catch it.

func (*HandlebarsEngine) Reload Uses

func (s *HandlebarsEngine) Reload(developmentMode bool) *HandlebarsEngine

Reload if set to true the templates are reloading on each render, use it when you're in development and you're boring of restarting the whole app when you edit a template file.

Note that if `true` is passed then only one `View -> ExecuteWriter` will be render each time, no concurrent access across clients, use it only on development status. It's good to be used side by side with the https://github.com/kataras/rizla reloader for go source files.

type INodeTag Uses

type INodeTag = pongo2.INodeTag

INodeTag type alias for pongo2.InodeTag

type JetArguments Uses

type JetArguments = jet.Arguments

JetArguments is a type alias of `jet.Arguments`, can be used on `AddFunc$funcBody`.

type JetEngine Uses

type JetEngine struct {

    // The Set is the `*jet.Set`, exported to offer any custom capabilities that jet users may want.
    // Available after `Load`.
    Set *jet.Set
    // contains filtered or unexported fields
}

JetEngine is the jet template parser's view engine.

func Jet Uses

func Jet(directory, extension string) *JetEngine

Jet creates and returns a new jet view engine.

func (*JetEngine) AddFunc Uses

func (s *JetEngine) AddFunc(funcName string, funcBody interface{})

AddFunc should adds a global function to the jet template set.

func (*JetEngine) AddRuntimeVars Uses

func (s *JetEngine) AddRuntimeVars(ctx context.Context, vars JetRuntimeVars)

AddRuntimeVars sets or inserts runtime jet variables through the Iris Context. This gives the ability to add runtime variables from different handlers in the request chain, something that the jet template parser does not offer at all.

Usage: view.AddJetRuntimeVars(ctx, view.JetRuntimeVars{...}). See `view.AddJetRuntimeVars` if package-level access is more meanful to the code flow.

func (*JetEngine) AddVar Uses

func (s *JetEngine) AddVar(key string, value interface{})

AddVar adds a global variable to the jet template set.

func (*JetEngine) Binary Uses

func (s *JetEngine) Binary(assetFn func(name string) ([]byte, error), assetNames func() []string) *JetEngine

Binary optionally, use it when template files are distributed inside the app executable (.go generated files).

The assetFn and namesFn can come from the go-bindata library. Should act before `Load` or `iris.Application#RegisterView`.

func (*JetEngine) Delims Uses

func (s *JetEngine) Delims(left, right string) *JetEngine

Delims sets the action delimiters to the specified strings, to be used in templates. An empty delimiter stands for the corresponding default: {{ or }}. Should act before `Load` or `iris.Application#RegisterView`.

func (*JetEngine) DisableViewDataTypeCheck Uses

func (s *JetEngine) DisableViewDataTypeCheck(jetRangerRendererContextKey string) *JetEngine

DisableViewDataTypeCheck accepts a context key name to use to map the jet specific renderer and ranger over context's view data.

If "jetDataContextKey" is not empty then `ExecuteWriter` will not check for types to check if an element passed through `Context.ViewData` contains a jet.Renderer or jet.Ranger or both. Instead will map those with simple key data naming (faster). Also it wont check if a value is already a reflect.Value (jet expects this type as values).

Defaults to empty.

func (*JetEngine) ExecuteWriter Uses

func (s *JetEngine) ExecuteWriter(w io.Writer, filename string, layout string, bindingData interface{}) error

ExecuteWriter should execute a template by its filename with an optional layout and bindingData. See `DisableViewDataTypeCheck` too.

func (*JetEngine) Ext Uses

func (s *JetEngine) Ext() string

Ext should return the final file extension which this view engine is responsible to render.

func (*JetEngine) Load Uses

func (s *JetEngine) Load() error

Load should load the templates from a physical system directory or by an embedded one (assets/go-bindata).

func (*JetEngine) Reload Uses

func (s *JetEngine) Reload(developmentMode bool) *JetEngine

Reload if setted to true the templates are reloading on each render, use it when you're in development and you're boring of restarting the whole app when you edit a template file.

Note that if `true` is passed then only one `View -> ExecuteWriter` will be render each time, not safe concurrent access across clients, use it only on development state.

func (*JetEngine) SetLoader Uses

func (s *JetEngine) SetLoader(loader jet.Loader) *JetEngine

SetLoader can be used when the caller wants to use something like multi.Loader or httpfs.Loader of the jet subpackages, overrides any previous loader may set by `Binary` or the default. Should act before `Load` or `iris.Application#RegisterView`.

func (*JetEngine) String Uses

func (s *JetEngine) String() string

String returns the name of this view engine, the "jet".

type JetRuntime Uses

type JetRuntime = jet.Runtime

JetRuntime is a type alias of `jet.Runtime`, can be used on RuntimeVariable input function.

type JetRuntimeVars Uses

type JetRuntimeVars = jet.VarMap

JetRuntimeVars is a type alias for `jet.VarMap`. Can be used at `AddJetRuntimeVars/JetEngine.AddRuntimeVars` to set a runtime variable ${name} to the executing template.

type Parser Uses

type Parser = pongo2.Parser

Parser type alias for pongo2.Parser

type TagParser Uses

type TagParser = pongo2.TagParser

TagParser the function signature of the tag's parser you will have to implement in order to create a new tag.

'doc' is providing access to the whole document while 'arguments' is providing access to the user's arguments to the tag:

{% your_tag_name some "arguments" 123 %}

start_token will be the *Token with the tag's name in it (here: your_tag_name).

Please see the Parser documentation on how to use the parser. See `RegisterTag` for more information about writing a tag as well.

type Token Uses

type Token = pongo2.Token

Token type alias for pongo2.Token

type Value Uses

type Value = pongo2.Value

Value type alias for pongo2.Value

type View Uses

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

View is responsible to load the correct templates for each of the registered view engines.

func (*View) AddFunc Uses

func (v *View) AddFunc(funcName string, funcBody interface{})

AddFunc adds a function to all registered engines. Each template engine that supports functions has its own AddFunc too.

func (*View) ExecuteWriter Uses

func (v *View) ExecuteWriter(w io.Writer, filename string, layout string, bindingData interface{}) error

ExecuteWriter calls the correct view Engine's ExecuteWriter func

func (*View) Find Uses

func (v *View) Find(filename string) Engine

Find receives a filename, gets its extension and returns the view engine responsible for that file extension

func (*View) Len Uses

func (v *View) Len() int

Len returns the length of view engines registered so far.

func (*View) Load Uses

func (v *View) Load() error

Load compiles all the registered engines.

func (*View) Register Uses

func (v *View) Register(e Engine)

Register registers a view engine.

Package view imports 18 packages (graph) and is imported by 39 packages. Updated 2019-10-27. Refresh now. Tools for package owners.