In expressjs, Dustjs Multiple templates not working getting 500 Error: Template Not Found: template
my base dust template as below (template.dust)
<div class="page">
{+pageHeader}Hello World!{/pageHeader}
<div class="bodyContent">
{+bodyContent/}
</div>
<div class="footer">
{+pageFooter}
<hr>
<a href="/contactUs">Contact Us</a>
{/pageFooter}
</div>
</div>
And I am trying to call this base template inside my home.dust I am getting error as below
Express
500 Error: Template Not Found: template
at Object.load (C:\office\nodejs-example\express_example\node_modules\application-name\node_modules\dust\lib\dust.js:54:27)
at Chunk.partial (C:\office\nodejs-example\express_example\node_modules\application-name\node_modules\dust\lib\dust.js:407:15)
at body_0 (undefined:1:130)
at Array.0 (C:\office\nodejs-example\express_example\node_modules\application-name\node_modules\dust\lib\dust.js:34:7)
at EventEmitter._tickCallback (node.js:192:40)
"home.dust"
{>"template"/}
{<pageHeader}
{?username}
Welcome {username} <a href="/items">Items</a> | <a href='/logout'> Log Out</a>
{:else}
<form method="POST" action="/signin">
<label>Usename <input type="text" name="username" id="s-user"></label>
<input type="submit" class="submit" value="Login">
</form>
{/username}
{/pageHeader}
routes class method
exports.home = function(req, res){
res.render('home', {username : req.session.username});
};
To solve this problem I wrote: klei-dust which is a helper, like consolidate, to use dustjs-linkedin together with express 3.x. The primary difference between klei-dust and consolidate.dust is that the former don't need partials and base template paths relative to app root, and doesn't require you specifying template file extension as well.
Your index.dust
could then look like:
{>layout/}
{<content}
Body content...
{/content}
Given you have a layout.dust
in the same folder as index.dust
.
You are not alone with this problem and this issue has driven me crazy! The author of Express has explained, that there is an issue in consolidate (package which uses Dust in Express).
yeah there's an issue open in consolidate for this sort of thing,
these engines that do not provide
this mechanism are pretty clumsy right now
By: The author of Express(tjholowaychuk) from google groupes
Use dustjs-linkedin package with consolidate package (dustjs package is no longer maintained). Both are on npm. You can use dust templates with a layout by doing the following:
layout.dust
<body>
<h1>{title}</h1>
{+content}
This is the base content.
{/content}
</body>
index.dust (homepage partial)
{>"views/layout.dust"/}
{<content}
This is loaded from a partial.
{/content}
app.js
var dust = require('dustjs-linkedin')
, cons = require('consolidate');
app.engine('dust', cons.dust);
Full Example: https://github.com/chovy/express-template-demo