Classes
The following classes are available globally.
-
A
TemplateEngine
for Kitura that uses Stencil for templating.The file extension for templates using this engine is
stencil
. If the file extension of the template specified in the call toresponse.render
matches, this template engine will be invoked. If no extension is specified, and this engine has been set as the default viarouter.setDefault(templateEngine:)
, the extension will be applied automatically.Usage Example:
router.add(templateEngine: StencilTemplateEngine()) // An example of using a dictionary of [String: Any] parameters to be rendered router.get("/hello") { request, response, next in try response.render("StencilExample.stencil", context: ["name": "World!"]]) next() }
A second example, using type-safe templating. For more information, see: https://developer.ibm.com/swift/2018/05/31/type-safe-templating/
See more// A codable type containing structured data to be used in our template struct Friend: Codable { let firstName: String let lastName: String } // Structured data that we wish to render let friends = [Friend(firstName: "Jack", lastName: "Sparrow"), Friend(firstName: "Captain", lastName: "America")] // An example of using type-safe templating to render data from a Swift type router.get("/friends") { request, response, next in try response.render("MyStencil.stencil", with: friends, forKey: "friends") next() }
Declaration
Swift
public class StencilTemplateEngine : TemplateEngine