Revel now allows for using custom template engines, the process for building your own is as follows

###The Template Engine A template engine must implement the TemplateEngine interface. To register a new engine in Revel :

  • Define it as a module to be loaded in the app.conf.
  • In an init() function, which registers the engine in revel by calling:
    RegisterTemplateLoader(key string, loader func(loader *TemplateLoader) (TemplateEngine, error)) (err error)
  • Specify the template engines to be used by setting the template.engines configuration option to the names of the engine to be used (a comma delimited list).

Template Engine Interface

There is a helper struct called revel.EngineHandles which can be used to examine the view to check to see if it contains a shebang or a file extenstion that matches the name of the engine , see revel.GoEngine for some examples

Template Interface

  • Name() string Name of template
  • Content() []string The content of the template as a string (Used in error handling).
  • Render(wr io.Writer, context interface{}) error Called by the server to render the template out the io.Writer, context contains the view args to be passed to the template.
  • Location() string // The full path to the file on the disk.

There is a helper struct called revel.TemplateView, which implements the Location function, see revel.GoEngine for some examples

GoDoc Reference
GitHub Labels