{"action":"created","issue":{"url":"https://api.github.com/repos/meteor/meteor/issues/3249","labels_url":"https://api.github.com/repos/meteor/meteor/issues/3249/labels{/name}","comments_url":"https://api.github.com/repos/meteor/meteor/issues/3249/comments","events_url":"https://api.github.com/repos/meteor/meteor/issues/3249/events","html_url":"https://github.com/meteor/meteor/issues/3249","id":51207876,"number":3249,"title":"Template.currentData behaves differently in helpers and event handlers","user":{"login":"mitar","id":585279,"avatar_url":"https://avatars.githubusercontent.com/u/585279?v=3","gravatar_id":"","url":"https://api.github.com/users/mitar","html_url":"https://github.com/mitar","followers_url":"https://api.github.com/users/mitar/followers","following_url":"https://api.github.com/users/mitar/following{/other_user}","gists_url":"https://api.github.com/users/mitar/gists{/gist_id}","starred_url":"https://api.github.com/users/mitar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitar/subscriptions","organizations_url":"https://api.github.com/users/mitar/orgs","repos_url":"https://api.github.com/users/mitar/repos","events_url":"https://api.github.com/users/mitar/events{/privacy}","received_events_url":"https://api.github.com/users/mitar/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/meteor/meteor/labels/Project:Blaze","name":"Project:Blaze","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2014-12-07T05:18:49Z","updated_at":"2015-03-17T21:56:43Z","closed_at":null,"body":"Currently there is a big difference how `Template.currentData()` behaves inside a event handler and template helper. In event handler it returns always the data context at the top level of a template where event handler was defined (and `this` is a data context of where event was triggered).\r\n\r\nBut for template helper it is always where the template is rendered. So if one is using `Template.currentData()` to access the template-level data context in the event handler, you have to use `Blaze.getData(Template.instance().view)` to access the same template-level data context in the template helper. So reusing the code and learned behavior between event handlers and template helpers is hard and it leads to programming bugs.\r\n\r\nSee example:\r\n\r\nhttps://github.com/mitar/meteor-issue3249\r\n\r\nAs example also shows, `Template.parentData` would not be a suitable approach here because the same code is used at various level of data contexts."},"comment":{"url":"https://api.github.com/repos/meteor/meteor/issues/comments/82614471","html_url":"https://github.com/meteor/meteor/issues/3249#issuecomment-82614471","issue_url":"https://api.github.com/repos/meteor/meteor/issues/3249","id":82614471,"user":{"login":"mitar","id":585279,"avatar_url":"https://avatars.githubusercontent.com/u/585279?v=3","gravatar_id":"","url":"https://api.github.com/users/mitar","html_url":"https://github.com/mitar","followers_url":"https://api.github.com/users/mitar/followers","following_url":"https://api.github.com/users/mitar/following{/other_user}","gists_url":"https://api.github.com/users/mitar/gists{/gist_id}","starred_url":"https://api.github.com/users/mitar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitar/subscriptions","organizations_url":"https://api.github.com/users/mitar/orgs","repos_url":"https://api.github.com/users/mitar/repos","events_url":"https://api.github.com/users/mitar/events{/privacy}","received_events_url":"https://api.github.com/users/mitar/received_events","type":"User","site_admin":false},"created_at":"2015-03-17T21:56:43Z","updated_at":"2015-03-17T21:56:43Z","body":"BTW, I implemented a bit better lookup in [meteor-template-extension](https://github.com/aldeed/meteor-template-extension). In fact it is anyway very error prone to have to specify exact number of parents when trying to access data. So for me your `Spacebars.lookup` would be just a workaround around `Template.currentData` issue and I will not be using `..` feature. So I am not sure how useful it is for you to complicate with `..` and so on.\r\n\r\nBecause for me using more declarative way when searching for parent data context and using `Template.parentData(fun)` is much better. I can then search for a data context which is an instance of my component system and it works. No matter how many other temporary data contexts were maybe added. And sometimes it is even impossible to specify a fixed value. Because when template is included in one location it might have different number of data contexts than in another location. And you want your event handlers to work in both cases."}}