{"action":"created","issue":{"url":"https://api.github.com/repos/olado/doT/issues/92","repository_url":"https://api.github.com/repos/olado/doT","labels_url":"https://api.github.com/repos/olado/doT/issues/92/labels{/name}","comments_url":"https://api.github.com/repos/olado/doT/issues/92/comments","events_url":"https://api.github.com/repos/olado/doT/issues/92/events","html_url":"https://github.com/olado/doT/issues/92","id":19763633,"number":92,"title":"javascript scope","user":{"login":"smcmurray","id":1036479,"avatar_url":"https://avatars.githubusercontent.com/u/1036479?v=3","gravatar_id":"","url":"https://api.github.com/users/smcmurray","html_url":"https://github.com/smcmurray","followers_url":"https://api.github.com/users/smcmurray/followers","following_url":"https://api.github.com/users/smcmurray/following{/other_user}","gists_url":"https://api.github.com/users/smcmurray/gists{/gist_id}","starred_url":"https://api.github.com/users/smcmurray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smcmurray/subscriptions","organizations_url":"https://api.github.com/users/smcmurray/orgs","repos_url":"https://api.github.com/users/smcmurray/repos","events_url":"https://api.github.com/users/smcmurray/events{/privacy}","received_events_url":"https://api.github.com/users/smcmurray/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2013-09-19T15:55:33Z","updated_at":"2016-10-30T21:14:01Z","closed_at":null,"body":"I'm trying to load subtemplates dynamically. So I created a small function that retrieves a template file and compiles it. Then I use that function inside templates. So I have code that looks like this:\n\n```\n  var cache = {};\n  var compile = function(path){\n      if (!(path in cache))\n        cache[path] = doT.template($.ajax(path, {async: false}).responseText);\n      return cache[path];\n  };\n\n  var people = [\n    {\n      \"name\": \"Alice\",\n      \"gender\": \"female\"\n    },\n    {\n      \"name\": \"Bob\",\n      \"gender\": \"male\"\n    }\n  ];\n\n  $.get(\"/templates/list.dot\", function(r){\n    var t = doT.template(r);\n    t(people);\n  });\n```\n\nlist.dot could look like this:\n\n```\n{{~it :person}}\n  {{=compile(\"/templates/\"+ person.gender + \".dot\")(person)}}\n{{~}}\n```\n\nThe list.dot template compiles, but the resulting function fails to run, complaining that \"compile is not defined.\"\n\nHow do I get compile() into scope?\n"},"comment":{"url":"https://api.github.com/repos/olado/doT/issues/comments/257179718","html_url":"https://github.com/olado/doT/issues/92#issuecomment-257179718","issue_url":"https://api.github.com/repos/olado/doT/issues/92","id":257179718,"user":{"login":"epoberezkin","id":2769109,"avatar_url":"https://avatars.githubusercontent.com/u/2769109?v=3","gravatar_id":"","url":"https://api.github.com/users/epoberezkin","html_url":"https://github.com/epoberezkin","followers_url":"https://api.github.com/users/epoberezkin/followers","following_url":"https://api.github.com/users/epoberezkin/following{/other_user}","gists_url":"https://api.github.com/users/epoberezkin/gists{/gist_id}","starred_url":"https://api.github.com/users/epoberezkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/epoberezkin/subscriptions","organizations_url":"https://api.github.com/users/epoberezkin/orgs","repos_url":"https://api.github.com/users/epoberezkin/repos","events_url":"https://api.github.com/users/epoberezkin/events{/privacy}","received_events_url":"https://api.github.com/users/epoberezkin/received_events","type":"User","site_admin":false},"created_at":"2016-10-30T21:14:01Z","updated_at":"2016-10-30T21:14:01Z","body":"Two other approaches are either adding them to data properties or passing context into templating function and pass it through to sub-templates (using .call/.apply).\r\n\r\nProbably worth adding to doT 101 together with recursion #205."}}
{"actor":{"display_login":"epoberezkin"}}