irisview

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2022 License: MIT Imports: 4 Imported by: 0

README

IrisView

GoDoc Widget

goview support for Iris template.

Install

$ go get -u github.com/foolin/goview
$ go get -u github.com/foolin/goview/supports/irisview
Example
package main

import (
	"github.com/foolin/goview/supports/irisview"
	"github.com/kataras/iris/v12"
)

func main() {
	app := iris.New()

	// Register the goview template engine.
	app.RegisterView(irisview.Default())

	app.Get("/", func(ctx iris.Context) {
		// Render with master.
		ctx.View("index", iris.Map{
			"title": "Index title!",
			"add": func(a int, b int) int {
				return a + b
			},
		})
	})

	app.Get("/page", func(ctx iris.Context) {
		// Render only file, must full name with extension.
		ctx.View("page.html", iris.Map{"title": "Page file title!!"})
	})

	app.Listen(":9090")
}

Project structure:

|-- app/views/
    |--- index.html          
    |--- page.html
    |-- layouts/
        |--- footer.html
        |--- master.html
    

See in "examples/basic" folder

Iris example

More examples

See _examples/ for a variety of examples.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(e *ViewEngine) iris.Handler

Middleware Iris middleware wrapper.

func NewMiddleware

func NewMiddleware(config goview.Config) iris.Handler

NewMiddleware Iris middleware for multiple templates.

Types

type ViewEngine

type ViewEngine struct {
	*goview.ViewEngine
	// contains filtered or unexported fields
}

ViewEngine view engine for Iris.

func Default

func Default() *ViewEngine

Default returns a new default view engine.

func New

func New(config goview.Config) *ViewEngine

New new view engine for Iris.

func Wrap

func Wrap(engine *goview.ViewEngine) *ViewEngine

Wrap wraps a view engine for goview.ViewEngine.

func (*ViewEngine) ExecuteWriter

func (e *ViewEngine) ExecuteWriter(w io.Writer, filename string, _ string, bindingData interface{}) error

ExecuteWriter executes a template by its name. It supports multiple templates, see `NewMiddleware` and `Middleware` too.

func (*ViewEngine) Ext

func (e *ViewEngine) Ext() string

Ext returns the file extension, it's empty on this case because the goviw engine supports filenames without extension.

func (*ViewEngine) Load

func (e *ViewEngine) Load() error

Load does nothing here, templates are loaded through goview.

Jump to

Keyboard shortcuts

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