vibe.d beta banner
get vibe.d

Enum member 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).


enum compileDietFileMixin(string template_file, string stream_variable, ulong base_indent) = "import;\x0a" ~ "OutputStream stream__ = " ~ stream_variable ~ ";\x0a" ~ "auto output__ = StreamOutputRange(stream__);\x0a" ~ dietParser!template_file(base_indent);


void handleRequest(HTTPServerRequest req, HTTPServerResponse res)
	int this_variable_is_automatically_visible_to_the_template;
	mixin(compileDietFileMixin!("index.dt", "res.bodyWriter"));

Sönke Ludwig


© 2012-2015 RejectedSoftware e.K.


Subject to the terms of the MIT license, as written in the included LICENSE.txt file.