How to dynamically render partials?

Issue #3 resolved
Tiago Ribeiro created an issue

Hi, I'm having trouble figuring out how can i render different partials based on different objects.

If i have a set of partials : [ p1, p2, p3, p4....]

and a set of dudes: dudes = [ name:'Joe', partial:'p1' ]

trying to fetch the correct partial and render it like:

{{#dudes}}
   {{>dude.partial}}
{{/dudes}}

stipple will naturally fetch a partial named dudes.partial instead of a partial named p1, you see any possible solution for this?

Comments (5)

  1. Niel Drummond repo owner

    Not sure if this answers your question, but at the moment in stipple you must use a reference to the template in your context (see for example PartialsTest.hx.

    So if you have a partial variable var p1 = new Template ().fromString(...), then you should be able to do:

    dudes = [ name: 'Joe', partial: p1 ] (note, it's not a string but a reference).

  2. Tiago Ribeiro reporter

    Wow, that may work if p1 is rendered with the current context (witch is likely), i think that solved it, thanks.

  3. Tiago Ribeiro reporter

    Yes the example has this code new Template ().fromString("Dudes: {{>dude dudes}}) i didn't understood what it was doing but its passing it another context, great flexibility, worked, has all i need for now.

  4. Niel Drummond repo owner

    Ah, that's good to know... Some parts of this lib need some practical experience, so it's much appreciated that you're actively using it. Let me know if you find something too limiting..

  5. Log in to comment