2013-12-10 56 views
0

请帮忙模板。亲子模板(dust.js)

为前我有3个模板:

<!-- comment --> 
<div>{message}</div> 

<!-- comment list --> 
<div class="comment-list">{+content}No comments{/content}</div> 

<!-- wrapper --> 
<div class="wrapper">{+content/}</div> 

显示为:

-wrapper 
--comments-list 
---comment 

我尝试:

{<content} 
    {#comments} 
     {>comment/} 
    {/comments} 
{/content} 
{<content} 
    {>comment-list /} 
{/content} 
{>worklet/} 

但这行不通。我做错了什么?

回答

0

我可以看到一些可能出现的问题:

{! First definition of the inline partial "content" !} 
{<content} 
    {#comments} 
     {>comment/} 
    {/comments} 
{/content} 

{! Second definition inline partial "content" will over-write the first definition !} 
{<content} 
    {>comment-list /} 
{/content} 

{! You are including a partial called "worklet", but where is this partial 
    defined. In your example, you call it "wrapper" !} 
{>worklet/} 

这里是一个可能的替代方案,可以为您的工作需要:

{! wrapper template !} 
<div class="wrapper"> 
    {?comments} 
     <ul class="comment-list"> 
      {#comments} 
       {>comment/} 
      {/comment} 
     </ul> 
    {:else} 
     No comments. 
    {/comments} 
</div> 

和评论模板:

{! comment template !} 
<li>{message}</li> 
+0

这是简单的方法。 但如果需要使用内容中的内容来创建两个或更多包装器? – user3071368

+0

没有更多关于你想要达到的内容的背景,我不知道如何回答你的问题。 – smfoote

+0

现在我明白{ user3071368