I am trying to generate a Flickr url based on a Flickr API call, and then return that result to a handlebars.js template. I am struggling to find a way around asynchronous p
Use Session
as an intermediary. It is reactive so as soon as its set it will change the template with the new data:
Template.backgroundImage.background = function(){
return Session.get("FlickrObject");
};
Template.backgroundImage.created = function() {
FlickrRandomPhotoFromSet(setID,function(){
Session.set("FlickrObject", FlickrObject)
});
}
So the created
method will be run when the template is created to run FlickrRandomPhotoFromSet
, when the result is returned it will set the Session hash which in turn will set the background as soon as the result is received.
Be careful with your FlickrRandomPhotoFromSet
too, I didn't notice you had an argument for FlickrObject
to pass to the callback.