Passing 'this' to template


#1

I love the way meteor will pass this automatically pass this and the data context to the child template.

But when I add another customize parameter. the data context stop passing

{{> child}} // this will pass the helper and data context
{{> child view=view}} // this will only pass the ‘view’

How do I let this working?


#2

{{> child this=this view=view}}


#3

Thanks that was fast!


#4

That doesn’t work! How to pass it ?


#5

I didn’t try the recently added let keyword, but it should do the trick:

{{#let view=view}}
  {{> child}}
{{/let}}

#6

it does work and it is answer to your question.
it defines data context, better said it defines “this” and “view” in data context,
so to access any of these, you need to use that this.something, view.something.
In root of data context would be these 2 objects.


#7

“this” is the parent root data context and view is like this.view.

In {{> child this=this view=view}}
does that mean I have to call this.this to access it instead of just this?
and get this.view to get view?

What if I want to get this and this.view?

My current solution is to use {{> child self}}
var self = this
self.view =view;
return self;
to add view to this and pass this.

let is cool! Is it only in meteor 1.2?
Still doesn’t upgrade to 1.2 since some package have issue with less.

Sincerely,


#8

My current solution is simply to install Blaze Components and forget about all the problems with data context. Why worry about unimportant things when Blaze Components takes care of them by default?


#9

How exactly Blaze Components affect problems with data context?
I dont see the connection here.


#10

Thanks for the suggestion. But I think later I’ll try the react approach or wait for Blaze 2