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;
                        p Item #{ num + extvar }
                //- 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;
                        p Item #{ num + (int)context["extvar"] }
                //- Unescaped output
                p Prints 8: !{ min(10, 2*6, 8) }

or whatever

I 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.
  • Deit variable referencing Jason Jeffory via Digitalmars-d-learn
    • Re: Deit variable referen... Martin Tschierschke via Digitalmars-d-learn

Reply via email to