Deit variable referencing

Jason Jeffory via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 1 16:15:32 PST 2016


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


More information about the Digitalmars-d-learn mailing list