March 2020
Intermediate to advanced
392 pages
10h 10m
English
Vapor provides a template system called Leaf. Leaf allows you to write templates with some logic in them and interact with controllers. Leaf templates end with *.leaf and are usually stored in the /Resources/Views folder.
Conveniently, you can return the rendering of a view as an EventLoopFuture type directly:
app.get("myTemplate") { req -> EventLoopFuture<View> in return req.view.render("example", ["name": "Vapor"]) }
In this case, /myTemplate is returning the content of example.leaf in the /Resources/Views folder and is passing forward a "name" variable that is set to "Vapor". The template should look like this:
Hi #(name)!
If you need to show HTML pages with Vapor, you should check out the extensive documentation that is available ...
Read now
Unlock full access