stencilproject/Stencil

How to integrate into the vapor or perfect?

kuhippo opened this issue · 1 comments

How to integrate into the vapor or perfect?
kylef commented

As the README shows, you can use Stencil like so:

import Stencil

struct Article {
  let title: String
  let author: String
}

let context = [
  "articles": [
    Article(title: "Migrating from OCUnit to XCTest", author: "Kyle Fuller"),
    Article(title: "Memory Management with ARC", author: "Kyle Fuller"),
  ]
]

let environment = Environment(loader: FileSystemLoader(paths: ["templates/"]))
let rendered = try environment.renderTemplate(name: context)

print(rendered)

renderTemplate will return a string that allows you to return in a HTTP message body from Vapor or Perfect.