javascript - meteor display first element of array in template spacebars -
i want display in template first element of array. i've seen many topics including this one doesn't work in case.
i have helper this:
template.home.helpers({ posts() { return posts.find({}); } });
i in template:
{{posts.[0].title}}
i don't want use findone in case.
best @ helper level, example, add optional index argument posts helper:
template.home.helpers({ posts(index) { if(typeof index !== "undefined" && index !== null){ var data = posts.find(); return data[index]; } else{ return posts.find(); } } });
then set data context , call in blaze this:
{{#with posts 0}} {{title}} {{/with}}
Comments
Post a Comment