Meteor.js - Using pathFor with a "foreign key"

Viewed 890

I have a Posts collection where each Post in the collection has a userId property. On my post detail page, I want to wrap the user's name with a link to their profile using the pathFor helper. If I just inlcude {{pathFor 'userProfile'}}, it sets up the link with the Post's _id, as one would expect, but I obviously need the userId in the link.

I've tried creating a second data context on the template's helper like so, but this didn't work either.

Script:

Template.postPage.helpers({
    user: function () {
        return {_id: this.userId};
    }      
});

Template:

<template name="postPage">
    {{#with user}}<a href="{{pathFor 'userProfile'}}">{{/with}}{{author}}</a>
</template>

How would I go about using pathFor with the userId field from my Post doc, instead of the _id field from my Post doc?

I'm using iron-router if that matters.

2 Answers
Related