Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handlebars + Meteor + iron-router

I am using iron-router for my meteor project and everything was going fine but I just ran into some strange behavior.

I have a loop set up for a list of items that looks something like this.

{{#each list_items}}
  <div>{{user.username}}
    <a href="{{link}}">Click here!</a>
  </div>
{{/each}}

The JSON object for my user looks something like this:

{
  user: {
      username: jdoe
    },
  images: {
    low-res-url: http://example.com
  },
  link: http://example.com/profile
}

Now the {{user.username}} shows up as expected but when I try to put the {{link}} in the href I get an error from iron-router saying

"You called Router.path for a route named undefined but that that route doesn't seem to exist. Are you sure you created it?" 

Any help or advice would be appreciated.

like image 439
Kris Hamoud Avatar asked Jan 11 '23 22:01

Kris Hamoud


2 Answers

Under the hood Iron-Router registers handelbars helper:

Handlebars.registerHelper('link', function (options) {                          
  ...
}); 

Simply change field link to different name like my_link.

like image 150
Kuba Wyrobek Avatar answered Jan 23 '23 13:01

Kuba Wyrobek


As @perhelium mentioned Iron-Router has specified a helper named 'link'

Handlebars.registerHelper('link', function (options) {...});

In order to access an item named 'link' in your JSON object you need to explicitly refer to the JSON object itself.

So your line: <a href="{{link}}">Click here!</a>

Would need to be specified as <a href="{{this.link}}">Click here!</a>

like image 37
joshorig Avatar answered Jan 23 '23 14:01

joshorig