Open aslakhellesoy opened 13 years ago
I found a workaround. My template:
{#nth o="names" n="1"}{title} {name}{~n}{/nth}
My context:
{
"title": "Sir",
"names": [{
"name": "Moe"
},
{
"name": "Larry"
},
{
"name": "Curly"
}],
nth: function(chunk, context, bodies, params) {
return context.current()[params.o][params.n];
}
}
Result:
Sir Larry
It would be nice to be able to just do this though:
{#names[1]}}{title} {name}{~n}{/names}
Would you consider adding this (or something similar) to dust?
+1
Is this still the only way to access an array item?
hi guys, we are maintaining and improving dust for Linkedin and we have mantained the repo as opensource. Now I have implemented what you were talking in this thread and it will be ready as soon as this pull request is merged. if you want, take a look! and anything you need just tell me. https://github.com/linkedin/dustjs/pull/33 Jairo
Fantastic!
it is ready now !
I couldn't find a mailing list, so here goes:
I'm trying to access only the first element of an array in my template:
However, that gives me a syntax error. Is it possible to access only the first element, or do I need to write a function for this?
Thanks for a great lib!