Access parent template data with Flow Router

2019-07-13 03:23发布

问题:

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:

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