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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -