-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
@index in Blaze #each #3716
@index in Blaze #each #3716
Conversation
Regular #each ({{#each items}}) sets a new data context for each child view to the item of the sequence. The new #each ({{#each item in items}}) preserves the data context and extends it to have the variable like 'item'
Remove the old implementation with modifying the data context, implement it in the new way to keep the same data context but lookup iterator in the scope.
no tests or docs yet
+1 Yep; useful handlebars functionality that's currently missing. Is it also present in template helper context? |
@hitchcott no, I tried hard not to put it there. It is confusing that things like these are implemented in the data context in handlebars.js, I implemented them as local scoping that can be looked up within the template. |
@@ -22,7 +22,7 @@ var unicodeClass = function (abbrev) { | |||
// Match one or more characters that can start an identifier. | |||
// This is IdentifierStart+. | |||
var rIdentifierPrefix = new RegExp( | |||
"^([a-zA-Z$_]+|\\\\u[0-9a-fA-F]{4}|" + | |||
"^(@?[a-zA-Z$_]+|\\\\u[0-9a-fA-F]{4}|" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean we support all kinds of identifiers with @
now? Or is there validation somewhere else which restricts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I will change it to just accept '@Index' and nothing else starting with '@'
moving this to the each-in PR. I will address Sashko's comments there. |
Where is "each-in PR"? It would be great if this would be available inside a template helper. Then one could do a helper which returns something only for odd or even values. |
You can always pass it as an argument. Each-in is here: #3560 |
Is this merged in? {{@Index}} in templates does not work. |
@patmoore it has been merged long time ago, but it hasn't been release. |
How frustrating! since it is in the docs. |
Gah. Just spent the last hour trying to figure out how to do this. Hope to see this in the 1.2 release.... |
@awatson1978 yep, it's going to be in 1.2! |
👍 |
@Slava 👍 👍 |
Wohoo |
I wanted to use this since it was in the docs, but it failed. Now I read it's an error in the docs. Weird. |
Any way to access the index value from inside a helper? Edit: I see your message above saying you tried to avoid this. I agree that keeping it out of the data context is good, however I wish it were stored somewhere in the template instance so that I could access it from helpers, events and onRendered. |
just pass it to the helper, it is not that terrible: {{#each person in people}}
{{myHelper @index}}
{{/each}} Template.bla.helpers({
myHelper: function (index) {
// do what you want
}
}); |
wip