Get value returned from another method

45 Views Asked by At

In a Template helper, is it possible to get from a method a value returned by another method?

In example

Template.postsList.helpers({
  posts: function () {
    return Posts.find({});
  },
  nextPath: function () {
    // how to return here the number of posts from the query
    // in the posts method?
  }
});
1

There are 1 best solutions below

0
On BEST ANSWER

You can just refactor the code so you have a shared way to obtain the posts cursor:

var postsCursor = function() {
  return Posts.find();
};

Template.postsList.helpers
  posts: postsCursor,
  nextPath: function () {
    var count = postsCursor().count();
    // do something with count
  }
});