How to pass parameter to sub-template in Blaze and don't kill context?


#1

I have an Article, object witch contains array of Translations. And translations contains array of Subjects.
const article = {translations:[ {translationId:"0", subjects:[...] }, {translationId:"1", subjects:[...] }, ...]

And I’m trying to write data from sub-template TagSubjects to parent template Article (into nested array witch is explained above).

{{#each tr in article.translations}}
  ...
  {{> TagsSubjects}}
  ...
{{/each}}

In that way , I have full access to parent Template instance, and I can write from TagsSubjects.js (just for testing) data like this:

template.data.translations[0].subjects.push(tagId)

And this data will be displayed and saved in Article.
But I don’t know how to pass translationId.

When I do

{{> TagsSubjects translationId=tr.translationId}}

or

{{> TagsSubjects translation=tr}}

I lose access to parent template Article.
How can I access to translationId from template.data in case of passing whole parent context to sub-template.
Or how can I access to parent template instance , after passing translationId to sub-template?
I tried use callback, but it didn’t help me (may be I did something wrong).
I’ve read this article from docs:
http://blazejs.org/guide/reusable-components.html


#2

If I understand correctly I’ve used callbacks for this successfully. Can you share your callback code?


#3

I deleted callback, and didn’t understand how it works… I made helper which returns parentTemplateInstance and pass it to child template. when I change something is child with that link, this data avaliable in parent too.


#4

This example app might help you.