Hi Sönke,
Thanks for reply. This works, but I need to send each rendering method. This is not good. What can I do?
app.d:
import vibe.d;
final class Service
{
void get()
{
string ver = "1.0.0";
render!("page.dt", ver);
}
void getTest()
{
render!("test.dt"); --> Error: undefined identifier 'ver'
}
}
shared static this()
{
auto router = new URLRouter;
router.registerWebInterface(new Service());
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, router);
logInfo("Please open http://127.0.0.1:8080/ in your browser.");
}
On Fri, 25 Mar 2016 11:40:35 GMT, Sönke Ludwig wrote:
> On Wed, 23 Mar 2016 11:58:38 GMT, can wrote:
>> I develop a web application and I need help. How do I pass variable layout.dt file or how can I show version number at layout.dt
>
> Anything that you pass to `render!()` will be available in the rendered template, as well as in any template that it includes and the one it derives from. So the following should work:
>
> layout.dt:
html
bodyp The version is #{ver} block main
page.dt:
extends layout
block main
p These are the page contents.app.d:
void getPage(HTTPServerRequest req, HTTPServerResponse res)
{
string ver = "1.0.0";
res.render!("page.dt", ver);
}