Search code examples
meteormeteor-helper

Meteor template helper location


I have an app structured like this:

myapp/
myapp/client/index.html
myapp/client/lib/helpers.js
myapp/server...

Inside helpers.js I have:

Template.game.helpers({

    game_id: function() {
        return '12345';
    }

});

Inside index.html I have:

<div>
    Game: {{> game }}

    <template name='game'>
        {{game_id}}
    </template>
</div>

I'm getting these errors below and the page displays completely blank:

Uncaught TypeError: Cannot read property 'helpers' of undefined
Uncaught Error: No such template: game

I'm using Meteor on Windows but I doubt this issue is Windows specific.


Solution

  • Templates need to be defined at the top level (outside of any other html tags). Change index.html to look something like:

    <body>
      Game: {{> game}}
    </body>
    
    <template name='game'>
      {{game_id}}
    </template>
    

    I'd recommend going through the tutorial on meteor.com.