Posted Tue, 26 Jan 2016 11:33:58 GMT in reply to
Martin Tschierschke
Reply
On Mon, 25 Jan 2016 10:39:11 GMT, Martin Tschierschke wrote:
Coming from the rails world, how do I implement a partial in vibe.d, so that a master template can consist of multiple diet templates? For example to render a "subscribe here" or "latest news ticker" or what ever part of the page which may appear on several other places on the website?
Best regards Martin
There are two main approaches built-in: Includes and D functions. Includes work just like for Jade templates:
html
body
include ticker.dt
ticker.d:
#ticker
- foreach (msg; news)
p= msg
If you need to customize the inserted partial, you can also define a function:
html
body
- void ticker(size_t max_messages)
#ticker
- foreach (msg; news[0 .. min($, max_messages))
p= msg
- ticker(10);
The function definition could also be in a separate .dt file, which is then included like in the former case.
Apart from this, you can of course also use client-side means provided by JS frameworks such as AngularJS.