Search code examples
templatesmeteormeteor-helper

Where to define a Meteor helper function that I can reuse in template helpers


For example, I have a function to get params from the URL. Where should I define it, so that I can use this function in my template helpers repeatedly?


Solution

  • Define the function in a lib folder under client. lib is loaded before files in client, so it will be accessible from all files in client. However, if you have files in subdirectories under client, lib will be loaded after them, so the helper won't be accessible from those deeper nested files.

    You may want to learn more about Structuring your app.

    The best strategy to control load order is to organize all your code in packages - the ultimate in modularity and reusability. Your helper function should be defined in a package that will be used throughout the app.

    See this excellent presentation on building large Meteor apps.