www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Request scoped information in Vibe.d

reply Venkat <venkatram.akkineni gmail.com> writes:
How do I make variables available to diet templates ? Java has 
request.setAttribute. Vibe.d's HTTPServerRequest has params and 
queryString. But by the looks of it, neither one of them is 
created for the purpose of temporary storage in the request. 
Where do I store request scoped information ?
Jul 21 2018
parent reply Johannes Loher <johannes.loher fg4f.de> writes:
On Sunday, 22 July 2018 at 06:21:40 UTC, Venkat wrote:
 How do I make variables available to diet templates ? Java has 
 request.setAttribute. Vibe.d's HTTPServerRequest has params and 
 queryString. But by the looks of it, neither one of them is 
 created for the purpose of temporary storage in the request. 
 Where do I store request scoped information ?
What is your usecase? If you simply want to pass a variable to a diet template, just pass it as a template parameter to render: /* ... */ int myVar = 42; render!("mytemplate.dt", myVar); /* ... */ Then in mytemplate.dt, you can do something like:
Jul 22 2018
parent reply Venkat <venkatram.akkineni gmail.com> writes:
On Sunday, 22 July 2018 at 08:43:23 UTC, Johannes Loher wrote:
 On Sunday, 22 July 2018 at 06:21:40 UTC, Venkat wrote:
 How do I make variables available to diet templates ? Java has 
 request.setAttribute. Vibe.d's HTTPServerRequest has params 
 and queryString. But by the looks of it, neither one of them 
 is created for the purpose of temporary storage in the 
 request. Where do I store request scoped information ?
What is your usecase? If you simply want to pass a variable to a diet template, just pass it as a template parameter to render: /* ... */ int myVar = 42; render!("mytemplate.dt", myVar); /* ... */ Then in mytemplate.dt, you can do something like:
That is what I want to do. But what if I am redirecting the user with some form errors ? In that case I am not using render!.
Jul 22 2018
parent Johannes Loher <johannes.loher fg4f.de> writes:
On Sunday, 22 July 2018 at 18:21:21 UTC, Venkat wrote:
 On Sunday, 22 July 2018 at 08:43:23 UTC, Johannes Loher wrote:
 On Sunday, 22 July 2018 at 06:21:40 UTC, Venkat wrote:
 [...]
What is your usecase? If you simply want to pass a variable to a diet template, just pass it as a template parameter to render: /* ... */ int myVar = 42; render!("mytemplate.dt", myVar); /* ... */ Then in mytemplate.dt, you can do something like:
That is what I want to do. But what if I am redirecting the user with some form errors ? In that case I am not using render!.
Could you give a short example of what you are trying to do?
Jul 29 2018