Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a block helper that adds to the data context #5361

Closed
lorensr opened this issue Oct 4, 2015 · 3 comments
Closed

Provide a block helper that adds to the data context #5361

lorensr opened this issue Oct 4, 2015 · 3 comments

Comments

@lorensr
Copy link
Contributor

lorensr commented Oct 4, 2015

I was surprised to find that #let doesn't add to the data context:

<body>
  {{#let foo="bar"}}
    {{helper}}
  {{/let}}
</body>
Template.body.helpers
  helper: ->
    console.log @
    @foo

http://meteorpad.com/pad/GP54WkuYj9tdj7HrJ/Copy%20of%20Blank

I would expect to see bar on the page, but I get a blank page and an empty object logged to the console.

I see that this is by design:

"it doesn't change the data context"
https://github.com/meteor/meteor/tree/devel/packages/spacebars#let

I think it would be useful to have something that:

A. Doesn't overwrite the entire this like #with does
B. Does add fields to the context (or if there are already fields with the same name, overwrites only those fields)

Because:

1- Having access to the field in a helper is cleaner than always tacking it on to the arg list:

{{helper}}
helper: ->
  @foo

vs

{{helper foo}}
helper: (foo) ->
  foo

2- I don't know how to access foo from an event.

@mitar
Copy link
Contributor

mitar commented Oct 4, 2015

This is a duplicate of #5280.

@lorensr
Copy link
Contributor Author

lorensr commented Oct 4, 2015

Thanks!

@avital
Copy link
Contributor

avital commented Oct 6, 2015

Yup, #5280 is the relevant place for this conversation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants