{"action":"created","issue":{"url":"https://api.github.com/repos/twigphp/Twig/issues/1856","labels_url":"https://api.github.com/repos/twigphp/Twig/issues/1856/labels{/name}","comments_url":"https://api.github.com/repos/twigphp/Twig/issues/1856/comments","events_url":"https://api.github.com/repos/twigphp/Twig/issues/1856/events","html_url":"https://github.com/twigphp/Twig/issues/1856","id":108764132,"number":1856,"title":"Attribute Support in Macros","user":{"login":"srsgores","id":1750837,"avatar_url":"https://avatars.githubusercontent.com/u/1750837?v=3","gravatar_id":"","url":"https://api.github.com/users/srsgores","html_url":"https://github.com/srsgores","followers_url":"https://api.github.com/users/srsgores/followers","following_url":"https://api.github.com/users/srsgores/following{/other_user}","gists_url":"https://api.github.com/users/srsgores/gists{/gist_id}","starred_url":"https://api.github.com/users/srsgores/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/srsgores/subscriptions","organizations_url":"https://api.github.com/users/srsgores/orgs","repos_url":"https://api.github.com/users/srsgores/repos","events_url":"https://api.github.com/users/srsgores/events{/privacy}","received_events_url":"https://api.github.com/users/srsgores/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-28T23:08:36Z","updated_at":"2015-09-30T10:36:56Z","closed_at":null,"body":"I would like to see *overloaded* attribute support in macros:\r\n\r\n```\r\n{% macro definitionItem(term, value) %}\r\n\t{% if term and definition %}\r\n\t\t<dt>\r\n\t\t\t{{ term }}\r\n\t\t</dt>\r\n\t\t<dd {{ attributes }}>\r\n\t\t\t{{ definition }}\r\n\t\t</dd>\r\n\t{% endif %}\r\n{% endmacro %}\r\n```\r\n\r\nWhere instead of passing an inline array of attributes, the attributes can be specified in a template like so:\r\n\r\n```\r\n{{ definitionItem(\"user\", \"srsgores\")(class=\"github-user\") }}\r\n```\r\n\r\nWhich would result in:\r\n\r\n```\r\n<dt>srsgores</dt>\r\n<dd class=\"github-user\">srsgores</dd>\r\n```\r\n\r\n[Jade has this feature](http://jade-lang.com/reference/mixins/), and it makes macros (what they call *mixins* very versatile)."},"comment":{"url":"https://api.github.com/repos/twigphp/Twig/issues/comments/144350374","html_url":"https://github.com/twigphp/Twig/issues/1856#issuecomment-144350374","issue_url":"https://api.github.com/repos/twigphp/Twig/issues/1856","id":144350374,"user":{"login":"stof","id":439401,"avatar_url":"https://avatars.githubusercontent.com/u/439401?v=3","gravatar_id":"","url":"https://api.github.com/users/stof","html_url":"https://github.com/stof","followers_url":"https://api.github.com/users/stof/followers","following_url":"https://api.github.com/users/stof/following{/other_user}","gists_url":"https://api.github.com/users/stof/gists{/gist_id}","starred_url":"https://api.github.com/users/stof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stof/subscriptions","organizations_url":"https://api.github.com/users/stof/orgs","repos_url":"https://api.github.com/users/stof/repos","events_url":"https://api.github.com/users/stof/events{/privacy}","received_events_url":"https://api.github.com/users/stof/received_events","type":"User","site_admin":false},"created_at":"2015-09-30T10:36:56Z","updated_at":"2015-09-30T10:36:56Z","body":"Well, to get attributes inside the class, my solution would be to use an array argument:\r\n\r\n```twig\r\n{{ definitionItem(\"user\", \"srsgores\", {class:\"github-user\"}) }}\r\n```\r\n\r\nThis will give you an ``attributes`` array (or whatever name you use in your macro signature) in the macro, similar to what is there in Jade (except for the auto-escaping things, because it does not work on macro calls in Twig, but on display)"}}