echoview

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2021 License: MIT Imports: 3 Imported by: 0

README

EchoView

GoDoc Widget

goview support for echo template v4 version.

Install


go get -u github.com/foolin/goview-v4

go get -u github.com/foolin/goview/supports/echoview-v4

Example

package main

import (
	"github.com/foolin/goview/supports/echoview"
	"github.com/labstack/echo"
	"github.com/labstack/echo/middleware"
	"net/http"
)

func main() {

	// Echo instance
	e := echo.New()

	// Middleware
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	//Set Renderer
	e.Renderer = echoview.Default()

	// Routes
	e.GET("/", func(c echo.Context) error {
		//render with master
		return c.Render(http.StatusOK, "index", echo.Map{
			"title": "Index title!",
			"add": func(a int, b int) int {
				return a + b
			},
		})
	})

	e.GET("/page", func(c echo.Context) error {
		//render only file, must full name with extension
		return c.Render(http.StatusOK, "page.html", echo.Map{"title": "Page file title!!"})
	})

	// Start server
	e.Logger.Fatal(e.Start(":9090"))
}

Project structure:

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

See in "examples/basic" folder

Echo 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) echo.MiddlewareFunc

Middleware echo middleware wrapper

func NewMiddleware

func NewMiddleware(config goview.Config) echo.MiddlewareFunc

NewMiddleware echo middleware for func `echoview.Render()`

func Render

func Render(ctx echo.Context, code int, name string, data interface{}) error

Render html render for template You should use helper func `Middleware()` to set the supplied TemplateEngine and make `Render()` work validly.

Types

type ViewEngine

type ViewEngine struct {
	*goview.ViewEngine
}

ViewEngine view engine for echo

func Default

func Default() *ViewEngine

Default new default config view engine

func New

func New(config goview.Config) *ViewEngine

New new view engine

func Wrap

func Wrap(engine *goview.ViewEngine) *ViewEngine

Wrap wrap view engine for goview.ViewEngine

func (*ViewEngine) Render

func (e *ViewEngine) Render(w io.Writer, name string, data interface{}, c echo.Context) error

Render render template for echo interface

Jump to

Keyboard shortcuts

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