{"id":16382350,"url":"https://github.com/parisek/twig-attribute","last_synced_at":"2025-09-09T19:08:34.223Z","repository":{"id":57035957,"uuid":"330212504","full_name":"parisek/twig-attribute","owner":"parisek","description":"Twig Attribute Extension - collects, sanitizes, and renders HTML attributes in a nice way.","archived":false,"fork":false,"pushed_at":"2024-10-10T08:42:02.000Z","size":24,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T17:24:41.443Z","etag":null,"topics":["drupal","drupal-10","drupal-9","php","pimcore-bundle","symfony-bundle","timber","twig","twig-attribute","twig-extension"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/parisek/twig-attribute","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parisek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-16T17:02:34.000Z","updated_at":"2024-10-10T08:39:07.000Z","dependencies_parsed_at":"2024-10-28T15:24:11.478Z","dependency_job_id":"60344d96-aebe-4b44-beaf-e1336d5041c8","html_url":"https://github.com/parisek/twig-attribute","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"151edc132cecb50170becb714c464e4808aa7d10"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parisek%2Ftwig-attribute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parisek%2Ftwig-attribute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parisek%2Ftwig-attribute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parisek%2Ftwig-attribute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parisek","download_url":"https://codeload.github.com/parisek/twig-attribute/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245052662,"owners_count":20553162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drupal","drupal-10","drupal-9","php","pimcore-bundle","symfony-bundle","timber","twig","twig-attribute","twig-extension"],"created_at":"2024-10-11T04:05:04.498Z","updated_at":"2025-03-23T03:33:17.430Z","avatar_url":"https://github.com/parisek.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Twig Attribute Extension\n=======================\nTwig is desperately missing wrapper function to handle HTML Attributes. I borrowed great [Attribute](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Template%21Attribute.php/class/Attribute/11.x) class from Drupal. It collects, sanitizes, and renders HTML attributes in a nice way.\n\nThis package was created based on issue [#2664570 - Move Attribute classes under Drupal\\Component](https://www.drupal.org/project/drupal/issues/2664570) which created groundwork for using this class outside Drupal world. Unfortunately I had to copy code out because issue is still open. I hope issue will be merged soon, so I can switch to official component split off from Drupal core with proper attribution. Expected component should be available at [https://github.com/drupal/core-attribute](https://github.com/drupal/core-attribute)\n\n## Installation\n\nTwig Attribute Extension can be easily installed using [composer](http://getcomposer.org/)\n\n    composer require parisek/twig-attribute\n\n## Usage\n\n```php\n$twig = new Twig_Environment($loader);\n$twig-\u003eaddExtension(new Parisek\\Twig\\AttributeExtension());\n```\n\nTo use in a symfony project [register the extensions as a service](http://symfony.com/doc/current/cookbook/templating/twig_extension.html#register-an-extension-as-a-service).\n\n```yaml\nservices:\n  twig.extension.attribute:\n    class: Parisek\\Twig\\AttributeExtension\n    tags:\n      - { name: twig.extension }\n```\n\n## Template\n\n```twig\n{% set my_attribute = create_attribute() %}\n{%\n  set my_classes = [\n    'kittens',\n    'llamas',\n    isKitten ? 'cats' : 'dogs',\n  ]\n%}\n\u003cdiv{{ my_attribute.addClass(my_classes).setAttribute('id', 'myUniqueId') }}\u003e\n  {{ content }}\n\u003c/div\u003e\n```\n\n```twig\n\u003cdiv{{ create_attribute({'class': ['region', 'region--header']}) }}\u003e\n  {{ content }}\n\u003c/div\u003e\n```\n\nExamples were copied from [official Drupal documentation](https://www.drupal.org/docs/8/theming-drupal-8/using-attributes-in-templates).\n\n## Use Cases\n- [Drupal - Pattern Lab](https://patternlab.io/)  \n- [Wordpress - Timber](https://wordpress.org/plugins/timber-library/)\n- [Pimcore - Templates](https://pimcore.com/en)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparisek%2Ftwig-attribute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparisek%2Ftwig-attribute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparisek%2Ftwig-attribute/lists"}