0
votes

I'm trying to do something similar to the below code.(trying to print an partial inside a loop)

    {#projects
     {<greeting}
       Hello {.name}
     {/greeting}
    {/projects}

But im getting an output like below:

Hello
Hello
....

As you can see that partial is not printed inside the loop.

My actual code http://jsfiddle.net/WKxzb/1/

1

1 Answers

1
votes

Most of the documentation examples suggest something like this fiddle: http://jsfiddle.net/cnftm/

In short, in greeting.tl:

Hello, {name}!

then in projects.tl:

{#projects}
  {>greeting /}
{/projects}

If where you store name didn't happen to be named name:

{#projects}
  {>greeting name=someOtherVar /}
{/projects}

Anything you want to be parametrized has to be, ahem, passed as a parameter, and no body is supported.

The exception to these is blocks with inline partials, which are like this fiddle: http://jsfiddle.net/PWYBr/1/

In short, in greeting.tl:

Hello, {+name}Anonymous Coward{/name}!{~n}

then in projects.tl:

{#projects}
    {>greeting/}
    {<name}
        {name}
    {/name}
{/projects}

This works great for loops, but you can't reuse the greeting partial ANYWHERE else on the page... basically, whoever writes {<name} last wins, such that this will do weird things:

{>greeting/}
{<name}everybody{/name}

{#projects}
    {>greeting/}
    {<name}
        {name}
    {/name}
{/projects}