我有一个Posts
集合,集合中的每个Post
集合都有一个userId
属性。在我的帖子详细信息页面上,我想使用pathFor
帮助程序将用户名与指向其个人资料的链接一起包装起来。如果我只是 inlcude {{pathFor 'userProfile'}}
,它会设置与 Post 的链接_id
,正如人们所期望的那样,但我显然需要链接中的 userId。
我已经尝试像这样在模板的帮助器上创建第二个数据上下文,但这也不起作用。
脚本:
Template.postPage.helpers({
user: function () {
return {_id: this.userId};
}
});
模板:
<template name="postPage">
{{#with user}}<a href="{{pathFor 'userProfile'}}">{{/with}}{{author}}</a>
</template>
我将如何使用我的文档中的字段,而不是我的pathFor
文档中的字段?userId
Post
_id
Post
如果这很重要,我正在使用铁路由器。