Parent - child templates (dust.js)

245 Views Asked by At

Please, help with templates.

for ex i have 3 template:

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

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

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

Show as:

-wrapper
--comments-list
---comment

I try:

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

But this not work. What i do wrong?

1

There are 1 best solutions below

3
On

I can see a few possible problems:

{! 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/}

Here is a possible alternative that may work for your needs:

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

and the comment template:

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