2013-12-10 58 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