2

This is something I've come across a few times. I'd like to do

{{> subtemplate item foo="bar"}}

So that the data context in subtemplate has all the item fields plus a foo field. Don't see any way to do this in the docs

https://github.com/meteor/meteor/blob/devel/packages/spacebars/README.md

I know I could make my own helper combine to use like this: {{> subtemplate combine item "foo" "bar"}}, but am hoping there's a better way.

Loren
  • 13,903
  • 8
  • 48
  • 79
  • 1
    possible duplicate of [Pass parameters to template without overriding data context](http://stackoverflow.com/questions/28015971/pass-parameters-to-template-without-overriding-data-context) – Peppe L-G Feb 04 '15 at 10:51

1 Answers1

1

Can you use dynamic template to pass in your data context?

 {{> Template.dynamic template=template [data=data] }}

See http://docs.meteor.com/#/full/template_dynamic

William Shea
  • 378
  • 1
  • 10
  • `Template.dynamic` is used for dynamic templates, it does not introduce any new feature to the data context. – Peppe L-G Feb 04 '15 at 10:48
  • You still need to write your own helpers to pass the data context into the dynamic template, so it will be like `{{> Template.dynamic template=template data=getMyData }}` and the helper will be `Template.getMyData.helpers({ getMyData: function(item) { item.foo = 'bar'; return item } })` – William Shea Feb 04 '15 at 11:49