Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"yield" or "body" method? #32

Open
ryanflorence opened this issue Aug 8, 2011 · 1 comment
Open

"yield" or "body" method? #32

ryanflorence opened this issue Aug 8, 2011 · 1 comment

Comments

@ryanflorence
Copy link

A common use case is to have a layout like so

layout.dust

<h1>header</h1>
{=body}
<p>Footer</p>

And then have a template use that layout

home.dust

{>layout}
<p>I am the content</p>

Which would render:

<h1>header</h1>
<p>I am the content</p>
<p>Footer</p>

Right now I'm doing it like this:

layout.dust

<h1>header</h1>
{+body}{/body}
<p>Footer</p>

home.dust

{>layout/}
{<body}
<p>I am the content</p>
{/body}

Is the first way supported? If not, consider this a feature request :)

@vybs
Copy link

vybs commented Mar 29, 2012

We are using the second pattern,

initially it was a little confusing, but now we have got used to it ..

we use it for other things too

Most often we tend to reuse the same data in the template again and again ... One way to avoid been repetitive is use aliases. So a common question was, how does dust support this ?

Well, in dust there is more than one way neat way to do this.

Use Inline Partials

Inline partials never output content themselves, and are always global to the template in which they are defined, so the order of their definition has no significance.

Key points to note : They are global to the template., there is no ordering and can be defined anywhere

Step 1 create global alias

{<greeting}Hello, Hola{/greeting}

Step 2

{#names}
{.} {+greeting/}
{/names}

{#projects}
{.} {+greeting/}
{/projects}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants