2012-08-16 25 views
1

在expressjs多个模板,Dustjs多个模板不工作得到500错误:模板未找到:模板在expressjs,Dustjs不工作

我的基地灰尘模板如下(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> 

,我试图打电话给我home.dust这里面基本模板我得到如下错误

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} 

路线类方法

exports.home = function(req, res){ 
    res.render('home', {username : req.session.username}); 

}; 
+0

我在这里举了个例子......也让我发疯。 index.dust应该覆盖base.dust中的内容块:https://github.com/chovy/express-template-demo/tree/master/demo/views – chovy 2012-09-20 04:57:16

回答

0

使用dustjs,LinkedIn包巩固包(dustjs包已不再维护)的作者。两者都在npm上。

layout.dust

<body> 
    <h1>{title}</h1> 
{+content} 
This is the base content. 
{/content} 
    </body> 

index.dust(主页部分)

{>"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

1

你并不孤单与这个问题,这个问题让我想疯了! Express的作者解释说,合并中存在一个问题(使用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

方式:快递(tjholowaychuk)from google groupes

+0

我试过这个[包](https:/ /npmjs.org/package/klei-dust),它对Express 3.x非常有用。现在您可以使用多个模板的Dust了。 – appsunited 2012-10-01 13:29:14

2

为了解决这个问题,我写道:klei-dust这是一个帮手,像巩固一样,使用dustjs-linkedin和express 3.x. klei-dust和consolidationate.dust之间的主要区别在于前者不需要相对于应用程序根目录的partials和base模板路径,也不需要指定模板文件扩展名。

index.dust然后可能看起来像:

{>layout/} 
{<content} 
    Body content... 
{/content} 

鉴于你在同一个文件夹layout.dustindex.dust