MustacheTemplateEngine

public class MustacheTemplateEngine: TemplateEngine

A TemplateEngine for Kitura that uses GRMustache for templating.

The default file extension for templates using this engine is mustache. If you do not explicitly provide a file extension in the call to response.render then this extension will be applied automatically.

Usage Example:

   router.add(templateEngine: MustacheTemplateEngine())

   // An example of using a dictionary of [String: Any] parameters to be rendered
   router.get("/hello") { request, response, next in
       try response.render("MustacheExample.mustache", context: ["name": "World!"]])
       next()
   }

For more information on Mustache templating, see: https://www.kituranext.org/guides/templating/mustachetemplate.html

  • The file extension of files rendered by the KituraMustache template engine: mustache

    Declaration

    Swift

    public var fileExtension: String
  • Initializes a KituraMustache template engine.

    Declaration

    Swift

    public init()
  • Declaration

    Swift

    public func render<T: Encodable>(filePath: String, with value: T, forKey key: String?,
                                   options: RenderingOptions, templateName: String) throws -> String
  • Declaration

    Swift

    public func render(filePath: String, context: [String: Any]) throws -> String