Access parent template data with Flow Router

2019-07-13 03:24发布

I switched to Flow Router and I have a problem. how can I access the parent template data? with Iron Router the data was coming from router and was available inside the template, so if I wanted to access a parent data Template.parentData() was working. But in Flow Router the data is not coming from router, it comes from helpers and Template.parentData() doesn't have the data in it anymore!

<template name="myTemplate">
    {{#if Template.subscriptionsReady}}
      {{> showPost parentPost }}
      {{> newPost }}
    {{/if}}  
</template>

Template.myTemplate.helpers({
    parentPost: function(){ return Posts.findOne({...})}
});

Template.newPost.events({
    'submit .js-new-post':function(event,template){
         console.log(Template.parentData(1).parentPost);
}});

1条回答
Emotional °昔
2楼-- · 2019-07-13 04:04

You need to pass that data through to the Template.

E.g. {{> newPost parentPost=mydatahere}}

See more here: http://guide.meteor.com/blaze.html#name-data-contexts

查看更多
登录 后发表回答