Reputation: 433
I am trying to link to blog detail page from blog list, but the link does not work. What am I doing wrong here? this._id in the link is the correct id. This is my route
this.route('blogdetail', {
path: '/groupsmain/:_id/blogs/:paramOne',
template:'groupdetail',
yieldTemplates: {
'blogdetail': {to: 'dynamiccontent'}
},
controller: blogdetailController
});
Blog list's url is
http://localhost:3000/groupsmain/NQxvBfeNQE875HDRR/blogs
and this is my link for blog detail
<h3><a href="{{pathFor 'blogdetail' paramOne=this._id}}">{{this.title}}</a></h3>
Upvotes: 2
Views: 527
Reputation: 251
Looking at the current Iron Router's code (version 0.9.1), it looks like the pathFor
helper uses the context only if you don't pass any arguments explicitly in the helper call. It may be a bug, since the docs examples show you could mix both cases.
So you either have to pass both parameters in the pathFor
helper or have both values set in the context. You are passing only paramOne
in the helper and expecting that Iron Router gets the _id
parameter somewhere else. Try this:
<a href="{{pathFor 'blogdetail' _id=whicheverIdYouNeedHere paramOne=_id}}">{{title}}</a>
If whicheverIdYouNeedHere
is actually a property of the parent context, you can get it using the ..
keyword. You would end up with something like:
<a href="{{pathFor 'blogdetail' _id=../nameOfThePropertyFromTheParentContext paramOne=_id}}">{{title}}</a>
Upvotes: 0
Reputation: 19544
pathFor
takes parameters from the current data context, not from the arguments you pass to it. So you need to alter the context with #with
helper:
<a href="{{#with _id=_id paramOne=this._id}}{{pathFor 'blogDetail'}}{{/with}}">
Upvotes: 2