Variable compileDietFileMixin
Generates a diet template compiler to use as a mixin.
This can be used as an alternative to compileDietFile
or compileDietFileCompat
. It allows the template to use all symbols visible in the enclosing scope. In situations where many variables from the calling function's scope are used within the template, it can reduce the amount of code required for invoking the template.
Note that even if this method of using diet templates can reduce the amount of source code. It is generally recommended to use compileDietFile
(Compat) instead, as those facilitate a cleaner interface between D code and diet code by explicity documenting the symbols usable inside of the template and thus avoiding unwanted, hidden dependencies. A possible alternative for passing many variables is to pass a struct or class value to compileDietFile
(Compat).
Declaration
module vibe.templ.diet; // ... void compileDietFileMixin!(string template_file, string stream_variable); // ...
Examples
void handleRequest(HTTPServerRequest req, HTTPServerResponse res) { int this_variable_is_automatically_visible_to_the_template; mixin(compileDietFileMixin!("index.dt", "res.bodyWriter")); }
Authors
Sönke Ludwig
Copyright
© 2012 RejectedSoftware e.K.
License
Subject to the terms of the MIT license, as written in the included LICENSE.txt file.