How to dynamically render partials?
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)
-
repo owner -
reporter Wow, that may work if p1 is rendered with the current context (witch is likely), i think that solved it, thanks.
-
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. -
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..
-
repo owner - changed status to resolved
- Log in to comment
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).