Views - noppoMan/Slimane GitHub Wiki
Views return HTML data from your application. They can be created from pure HTML documents or passed through renderers such as Stencil or Your preferred template engines.
Stencil is a simple and powerful template language for Swift. It provides a syntax similar to Django and Mustache. If you're familiar with these, you will feel right at home with Stencil.
- Stencil: https://github.com/kylef/Stencil
- StencilViewEngine: https://github.com/slimane-swift/StencilViewEngine
1. Create View Directory
cd /path/to/YourApp/
mkdir ./Views
2. add Views/index.stencil
<html>
<head>
<title>{{name}}</title>
</head>
<body>
Welcome to {{name}}!
</body>
</html>
3. Respond to the renderd content with response.render
import Slimane
import StencilViewEngine
app.use(.get, "/") { request, response, responder in
var response = response
let stencil = StencilViewEngine(path: "index" , context: Context(dictionary: ["name": "Slimane"]))
response.render(with: stencil)
responder(.respond(response))
}
You can create own ViewEngine for Slimane.