Templating

Overview

Go-Mojito's Renderer interface provides a dependency-independent way to dependency inject a renderer into your handlers and middleware. By default, the built-in go template-based renderer is used, but you can easily replace it with a custom implementation like Infinytum Handlebars.

  • Built-in Implementation available
  • Can be replaced
  • Multi-Implementation suppported
  • Universal RendererContext

Of course you can also have multiple renderers injected by using named dependencies, even without replacing the builtin renderer.

Quick Start

  1. Create a new Go-Mojito Handler that has a mojito.RendererContext argument.

    func SomeHandler(ctx mojito.RendererContext) {}
  2. Go-Mojito will now detect that you want a renderer context injected into your handler, instead of a regular context.

  3. Create a template in resources/templates called quickstart.tpl

    Hello {{.name}}
  4. Make use of the renderer context instance

    func SomeHandler(ctx mojito.RendererContext) {
        ctx.ViewBag().Set("name", "world")
        ctx.View("quickstart")
    }

FAQ

No frequently asked questions yet!