Skip to content

Instantly share code, notes, and snippets.

Created April 14, 2012 20:48
Show Gist options
  • Select an option

  • Save anonymous/2387816 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/2387816 to your computer and use it in GitHub Desktop.
Example of using Meteor.methods() and Meteor.call()
if (Meteor.is_client) {
Template.hello.greeting = function () {
return "Welcome to XYZ.";
};
Template.hello.events = {
'click input' : function () {
// template data, if any, is available in 'this'
if (typeof console !== 'undefined')
console.log("You pressed the button");
console.log(Meteor.call('test', 1, function(e, r) {
console.log('e', e);
console.log('r', r);
}));
}
};
}
if (Meteor.is_server) {
Meteor.startup(function () {
// code to run on server at startup
Meteor.methods({
test: function(arg) {
console.log('test'+arg);
return 'test'+arg;
}
});
});
}
@rob-gordon

Copy link
Copy Markdown

This gist is really useful, but what if our template helper is meant to pass information back to the template to be rendered (not just logged in the console)?

@thdoan

thdoan commented Jul 22, 2015

Copy link
Copy Markdown

@brunodb3 Methods don't have to be defined inside Meteor.startup():

Source: http://meteortips.com/first-meteor-tutorial/methods/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment