{"action":"created","issue":{"url":"https://api.github.com/repos/at0g/nunjucks-loader/issues/41","repository_url":"https://api.github.com/repos/at0g/nunjucks-loader","labels_url":"https://api.github.com/repos/at0g/nunjucks-loader/issues/41/labels{/name}","comments_url":"https://api.github.com/repos/at0g/nunjucks-loader/issues/41/comments","events_url":"https://api.github.com/repos/at0g/nunjucks-loader/issues/41/events","html_url":"https://github.com/at0g/nunjucks-loader/issues/41","id":184223504,"number":41,"title":"require Macro does nothing","user":{"login":"jamesgorrie","id":31692,"avatar_url":"https://avatars.githubusercontent.com/u/31692?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesgorrie","html_url":"https://github.com/jamesgorrie","followers_url":"https://api.github.com/users/jamesgorrie/followers","following_url":"https://api.github.com/users/jamesgorrie/following{/other_user}","gists_url":"https://api.github.com/users/jamesgorrie/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesgorrie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesgorrie/subscriptions","organizations_url":"https://api.github.com/users/jamesgorrie/orgs","repos_url":"https://api.github.com/users/jamesgorrie/repos","events_url":"https://api.github.com/users/jamesgorrie/events{/privacy}","received_events_url":"https://api.github.com/users/jamesgorrie/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/at0g/nunjucks-loader/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-20T13:02:32Z","updated_at":"2016-10-22T13:49:56Z","closed_at":null,"body":"I have tried to include a macro into my app with no luck.\r\n\r\nI am not sure if this is something missing from Nunjucks' API ([report](https://groups.google.com/forum/?fromgroups#!topic/nunjucks/oNMdE7I5aSU)) or from the loader.\r\n\r\ne.g.\r\n```HTML\r\n{# macro.njk #}\r\n{% macro toggler(controlsId, expanded = true, attributes = {}, innerHTML = \"\") %}\r\n  {# make this a button #}\r\n  <a href=\"#\"\r\n    role=\"button\"\r\n    {% for attr, val in attributes %}\r\n      {{attr}}=\"{{val}}\"\r\n    {% endfor %}\r\n    data-component=\"show-hide\"\r\n    aria-controls=\"{{controlsId}}\"\r\n    aria-expanded=\"{{expanded}}\">\r\n    {{innerHTML | safe}}\r\n  </a>\r\n{% endmacro %}\r\n```\r\n\r\n```JS\r\n// app.js\r\nimport template from './location/to/macro/macro.njk';\r\n\r\n// Not sure what the syntax is here, I've dug around and can't fund anything.\r\nconst rendered = template.toggler.render({ expanded: true, controlsId: 'nav' });\r\nconsole.log(rendered);\r\n```"},"comment":{"url":"https://api.github.com/repos/at0g/nunjucks-loader/issues/comments/255529522","html_url":"https://github.com/at0g/nunjucks-loader/issues/41#issuecomment-255529522","issue_url":"https://api.github.com/repos/at0g/nunjucks-loader/issues/41","id":255529522,"user":{"login":"at0g","id":1406770,"avatar_url":"https://avatars.githubusercontent.com/u/1406770?v=3","gravatar_id":"","url":"https://api.github.com/users/at0g","html_url":"https://github.com/at0g","followers_url":"https://api.github.com/users/at0g/followers","following_url":"https://api.github.com/users/at0g/following{/other_user}","gists_url":"https://api.github.com/users/at0g/gists{/gist_id}","starred_url":"https://api.github.com/users/at0g/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/at0g/subscriptions","organizations_url":"https://api.github.com/users/at0g/orgs","repos_url":"https://api.github.com/users/at0g/repos","events_url":"https://api.github.com/users/at0g/events{/privacy}","received_events_url":"https://api.github.com/users/at0g/received_events","type":"User","site_admin":false},"created_at":"2016-10-22T13:49:56Z","updated_at":"2016-10-22T13:49:56Z","body":"> Problem is I want the JS to be able to create macros\r\n\r\ncreate or call?\r\n\r\nif you want to be able to call macro's from js, simple answer is you can't - AFAIK nunjucks does not support this - the macros need to be imported into a nunjucks template and then the template is rendered. eg.\r\n\r\n```\r\nvar app = express();\r\n\r\nnunjucks.configure('views', {\r\n    autoescape: true,\r\n    express: app\r\n});\r\n\r\napp.get('/', function(req, res) {\r\n    res.render('macro.njk'); // this won't work\r\n});\r\n```\r\n\r\nIf what you want is a callable template function that takes arguments, why not just use a template and pass the data context? You can then import and render the template from js."}}
{"actor":{"display_login":"at0g"}}