digitalmars.D.learn - Deit variable referencing
- Jason Jeffory (35/35) Jan 01 2016 Ok, So Deit allows D code inside html... looks great.
- Martin Tschierschke (6/41) Jan 03 2016 I am a very new at this, but I think "the solution" is to call
Ok, So Deit allows D code inside html... looks great. But how do external variables work? If I create a variable in the server(such as a class), can an html file access it easily? (not having to jump through hoops) doctype html html head title D string interpolations test body - import std.algorithm : min; p Four items ahead: - foreach( i; 0 .. 4 ) - auto num = i+1; //- Unescaped output p Prints 8: !{ min(10, 2*6, 8) } here, extvar is a int located somewhere else(other deit html file that has ran(hopefully) or vibe.d project that created it. (Obviously there has to be a way to get extvar) E.g., If deit can have a special variable called context that each html file can access and along with the vibe.d project, then we can easily pass the variable. doctype html html head title D string interpolations test body - import std.algorithm : min; p Four items ahead: - foreach( i; 0 .. 4 ) - auto num = i+1; //- Unescaped output p Prints 8: !{ min(10, 2*6, 8) } or whatever
Jan 01 2016
On Saturday, 2 January 2016 at 00:15:32 UTC, Jason Jeffory wrote:Ok, So Deit allows D code inside html... looks great. But how do external variables work? If I create a variable in the server(such as a class), can an html file access it easily? (not having to jump through hoops) doctype html html head title D string interpolations test body - import std.algorithm : min; p Four items ahead: - foreach( i; 0 .. 4 ) - auto num = i+1; //- Unescaped output p Prints 8: !{ min(10, 2*6, 8) } here, extvar is a int located somewhere else(other deit html file that has ran(hopefully) or vibe.d project that created it. (Obviously there has to be a way to get extvar) E.g., If deit can have a special variable called context that each html file can access and along with the vibe.d project, then we can easily pass the variable. doctype html html head title D string interpolations test body - import std.algorithm : min; p Four items ahead: - foreach( i; 0 .. 4 ) - auto num = i+1; //- Unescaped output p Prints 8: !{ min(10, 2*6, 8) } or whateverI am a very new at this, but I think "the solution" is to call res.render! with all alias names you need. Defining int extvar =... before; you use: res.render!("your-template.dt",extvar,..) hope this helps. Regards mt.
Jan 03 2016