dustjs icon indicating copy to clipboard operation
dustjs copied to clipboard

Extend partials

Open norlin opened this issue 12 years ago • 2 comments

For example, I have little html-snippet

<div class="my-little-block">
    <h3 class="title">{title}</h3>
    <div class="little-block-content">{content}</div>
</div>

How I could reuse this snippet in my template? E.g., I need template like this:

{?dust}
<div class="my-little-block">
    <h3 class="title">My first block</h3>
    <div class="little-block-content">
        <div>...more html with {some} {params}...</div>
    </div>
</div>
{:else}
<div class="my-little-block">
    <h3 class="title">Look ma, table!</h3>
    <div class="little-block-content">
        <table>some other html {with} {different} {data}</table>
    </div>
</div>
{/else}

And I want not to copy-paste html-layout for my little block, but use some partial with it. Now I can't do this...

Something like this:

{?cond}
    {>myLittleBlock}
        {<title}My first block{/title}
        {<content}
            <div>...more html with {some} {params}...</div>
        {/content}
    {/myLittleBlock}
{:else}
    {>myLittleBlock}
        {<title}Look ma, table!{/title}
        {<content}
            <table>some other html {with} {different} {data}</table>
        {/content}
    {/myLittleBlock}
{/cond}

norlin avatar Oct 08 '13 08:10 norlin

You seem to be looking for a template that can take simple parameters and large chunks of code as a parameter value. I've got a dust helper that should meet your needs.

http://rragan.github.io/dust-motes/docs/helpers-html.html https://github.com/rragan/dust-motes/blob/master/src/helpers/html/layout.js

Somewhat related is the @provide helper, combined with a simple partial it could do what you need.

http://rragan.github.io/dust-motes/docs/helpers-data.html https://github.com/rragan/dust-motes/blob/master/src/helpers/data/provide.js

rragan avatar Oct 09 '13 15:10 rragan

Related to PR #358

prashn64 avatar Dec 11 '13 00:12 prashn64