Reader small image

You're reading from  Echo Quick Start Guide

Product typeBook
Published inMay 2018
PublisherPackt
ISBN-139781789139433
Edition1st Edition
Tools
Right arrow
Author (1)
Ben Huson
Ben Huson
author image
Ben Huson

John Huson is an Echo developer
Read more about Ben Huson

Right arrow

Templates within Echo

The Echo framework does provide a facility for custom rendering which is based on the echo.Renderer interface. This interface stipulates that implementations have a method Render which will perform the rendering of data. With this convention, we are able to take what we learned about Go templates and apply those templates to implement a custom echo.Renderer that is capable of rendering HTML templates back to the caller. The following is a very minimal example of an echo.Renderer implementation that we have implemented in $GOPATH/src/github.com/PacktPublishing/Echo-Essentials/chapter8/handlers/reminder.go:

type CustomTemplate struct {
        *template.Template
}

func (ct *CustomTemplate) Render(w io.Writer, name string, data interface{},
        ctx echo.Context) error {
        return ct.ExecuteTemplate(w, name, data)
}

Within this code block, we are creating...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Echo Quick Start Guide
Published in: May 2018Publisher: PacktISBN-13: 9781789139433

Author (1)

author image
Ben Huson

John Huson is an Echo developer
Read more about Ben Huson