{"action":"created","issue":{"url":"https://api.github.com/repos/meteor/meteor/issues/3231","labels_url":"https://api.github.com/repos/meteor/meteor/issues/3231/labels{/name}","comments_url":"https://api.github.com/repos/meteor/meteor/issues/3231/comments","events_url":"https://api.github.com/repos/meteor/meteor/issues/3231/events","html_url":"https://github.com/meteor/meteor/pull/3231","id":50991084,"number":3231,"title":"Allow more direct access to specific template methods","user":{"login":"taromero","id":1489035,"avatar_url":"https://avatars.githubusercontent.com/u/1489035?v=3","gravatar_id":"","url":"https://api.github.com/users/taromero","html_url":"https://github.com/taromero","followers_url":"https://api.github.com/users/taromero/followers","following_url":"https://api.github.com/users/taromero/following{/other_user}","gists_url":"https://api.github.com/users/taromero/gists{/gist_id}","starred_url":"https://api.github.com/users/taromero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taromero/subscriptions","organizations_url":"https://api.github.com/users/taromero/orgs","repos_url":"https://api.github.com/users/taromero/repos","events_url":"https://api.github.com/users/taromero/events{/privacy}","received_events_url":"https://api.github.com/users/taromero/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":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-12-04T15:50:11Z","updated_at":"2015-02-11T00:58:01Z","closed_at":"2015-02-11T00:58:01Z","pull_request":{"url":"https://api.github.com/repos/meteor/meteor/pulls/3231","html_url":"https://github.com/meteor/meteor/pull/3231","diff_url":"https://github.com/meteor/meteor/pull/3231.diff","patch_url":"https://github.com/meteor/meteor/pull/3231.patch"},"body":"With the now deprecated Template declaration syntax, you could directly access template methods:\r\n\r\n``` javascript\r\nTemplate.myTemplate.myMethod = function() {\r\n  return 'result'\r\n}\r\n\r\nTemplate.myTemplate.myMethod() // outputs 'result'\r\n```\r\n\r\nWith the prefered way to declare helpers, you cannot directly access them:\r\n\r\n``` javascript\r\nTemplate.myTemplate.helpers({\r\n  myMethod: function() {\r\n    return 'result'\r\n  }\r\n})\r\n\r\nTemplate.myTemplate.myMethod() // outputs undefined\r\n\r\n// you have to call the method either through a getter\r\nTemplate.myTemplate.__helpers.get('myMethod')()\r\n\r\n// or though a hack\r\nTemplate.myTemplate.__helpers[' myMethod']() // notice the empty space before 'myMethod'\r\n```\r\n\r\nThis PR would allow to call it on a more direct way:\r\n\r\n``` javacript\r\nTemplate.myTemplate.__helpers.myMethod()\r\n```\r\n\r\nIs there a reason for adding the white spaces before the argument names on `HelperMap.prototype.set`?"},"comment":{"url":"https://api.github.com/repos/meteor/meteor/issues/comments/73817079","html_url":"https://github.com/meteor/meteor/pull/3231#issuecomment-73817079","issue_url":"https://api.github.com/repos/meteor/meteor/issues/3231","id":73817079,"user":{"login":"avital","id":37586,"avatar_url":"https://avatars.githubusercontent.com/u/37586?v=3","gravatar_id":"","url":"https://api.github.com/users/avital","html_url":"https://github.com/avital","followers_url":"https://api.github.com/users/avital/followers","following_url":"https://api.github.com/users/avital/following{/other_user}","gists_url":"https://api.github.com/users/avital/gists{/gist_id}","starred_url":"https://api.github.com/users/avital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avital/subscriptions","organizations_url":"https://api.github.com/users/avital/orgs","repos_url":"https://api.github.com/users/avital/repos","events_url":"https://api.github.com/users/avital/events{/privacy}","received_events_url":"https://api.github.com/users/avital/received_events","type":"User","site_admin":false},"created_at":"2015-02-11T00:58:01Z","updated_at":"2015-02-11T00:58:01Z","body":"The code could have been commented better -- the intention for the spaces is to let you define helpers such as \"toString\".\r\n\r\nMoreover, it's actually good to have an explicit layer of abstraction so that people /don't/ call helpers across templates. Here's why: when someone goes to change the implementation of a helper, the expectation is typically that the helper is only used within that particular template. So, a better pattern is to explicitly extract the code that you'd like to reuse into a function that's called from helpers in the different templates."}}