This is definitely a noob question but what is the proper way to extract the database information and display it on the webpage? I am able to output it to the console just fine.
Or, to ask a different way, how do I take the information in a variable in app.d and display it in a diet template?
On Wed, 23 Jul 2014 01:58:07 GMT, BigRed wrote:
This is definitely a noob question but what is the proper way to extract the database information and display it on the webpage? I am able to output it to the console just fine.
Or, to ask a different way, how do I take the information in a variable in app.d and display it in a diet template?
You can pass arbitrary variables as additional template arguments to render!()
. So a simple MongoDB query could look like this:
MongoCollection s_collection;
void handleRequest(HTTPServerRequest req, HTTPServerResponse res)
{
auto results = s_collection.find();
render!("results.dt", results);
}
results.dt:
doctype 5
html
body
p Results:
ul
- foreach (r; results)
li= r.toJson().toString()