If the helper is in the same file, is there no way to call the sayHello method without registering it as a global helper? I’ve been trying to figure out how to write reusable code, and it seems like things like this are making it really tough. But I’m sure that I’m just missing something here.
A helper is used to connect Blaze templates to logic, it’s not a normal function. The return values of a helper function are returned to the Blaze template, so you could call your helper function via {{sayHello}} there. Calling a helper function from an event handler wouldn’t make much sense.
To achieve what you probably want (= a local function that you can call from an event handler), you would write:
If you want to write a lot of reusable code / components, I can recommend you www.viewmodel.org for Blaze - it makes things much easier. In your case above, you need to write the sayHello method once and could use it as template helper and within your events.
Omg. Thank you so much. I don’t know why I was under the impression that all of my methods had to be nested inside of the Meteor functions (onCreated, helpers, events, etc…)
You might also want to take a look at space:template-controller. It pairs very well with the 1.3 Guide and you can define private helper methods accessible in your .js file only. You can read the simple API here.