{"id":24764075,"url":"https://github.com/stillat/statamic-attribute-renderer","last_synced_at":"2026-02-28T18:04:01.693Z","repository":{"id":206668090,"uuid":"717432747","full_name":"Stillat/statamic-attribute-renderer","owner":"Stillat","description":"A simple utility addon for Statamic that provides a simple way to render HTML attributes, with advanced variable handling features.","archived":false,"fork":false,"pushed_at":"2024-05-11T20:02:28.000Z","size":64,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-20T05:56:53.463Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Stillat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":"JohnathonKoster"}},"created_at":"2023-11-11T13:29:18.000Z","updated_at":"2025-03-01T00:00:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"f77709ac-54b7-4460-87fc-e0286e370585","html_url":"https://github.com/Stillat/statamic-attribute-renderer","commit_stats":null,"previous_names":["stillat/statamic-attribute-renderer"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Stillat/statamic-attribute-renderer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stillat%2Fstatamic-attribute-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stillat%2Fstatamic-attribute-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stillat%2Fstatamic-attribute-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stillat%2Fstatamic-attribute-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Stillat","download_url":"https://codeload.github.com/Stillat/statamic-attribute-renderer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stillat%2Fstatamic-attribute-renderer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29946464,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T17:57:52.716Z","status":"ssl_error","status_checked_at":"2026-02-28T17:57:31.974Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-01-28T21:32:26.008Z","updated_at":"2026-02-28T18:04:01.670Z","avatar_url":"https://github.com/Stillat.png","language":"PHP","funding_links":["https://github.com/sponsors/JohnathonKoster"],"categories":[],"sub_categories":[],"readme":"# Attribute Renderer for Statamic\n\nAttribute Renderer is a utility addon that helps create HTML attribute strings from arrays.\n\nAt a high level, it allows you to convert something like this:\n\n```php\n\u003c?php\n\nuse function Stillat\\StatamicAttributeRenderer\\attributes;\n\nattributes([\n    'name' =\u003e 'author',\n    'content' =\u003e 'John Doe'\n]);\n```\n\nto the following HTML attribute string:\n\n```html\nname=\"author\" content=\"John Doe\"\n```\n\nThe attributes renderer is also context aware, and can do things like this:\n\n```php\n\u003c?php\n\nuse function Stillat\\StatamicAttributeRenderer\\attributes;\n\nattributes([\n    'name' =\u003e 'author',\n    'content' =\u003e '$author'\n], [\n    'author' =\u003e 'John Doe'\n]);\n```\n\nThese examples are basic, and Attribute Renderer supports even more complex scenarios.\n\n## How to Install\n\nAttribute Renderer can be installed by running the following command from the root of your project:\n\n``` bash\ncomposer require stillat/statamic-attribute-renderer\n```\n\n## Converting Arrays to Attribute Strings\n\nThe simplest way to convert a key/value array of attribute details to a string is using the `attributes` utility function:\n\n```php\n\u003c?php\n\nuse function Stillat\\StatamicAttributeRenderer\\attributes;\n\nattributes([\n    'name' =\u003e 'author',\n    'content' =\u003e 'John Doe'\n]);\n```\n\nwhich produces the following result:\n\n```html\nname=\"author\" content=\"John Doe\"\n```\n\n## Resolving Variable Values\n\nWe can resolve variables from contextual data, which is supplied as the second argument to the `attributes` function. When specifying variable names, we simply prefix them with the `$` symbol:\n\n```php\n\u003c?php\n\nuse function Stillat\\StatamicAttributeRenderer\\attributes;\n\nattributes([\n    'name' =\u003e 'author',\n    'content' =\u003e '$author'\n], [\n    'author' =\u003e 'John Doe'\n]);\n```\n\nWe can use `$$` to escape the beginning of a variable string to emit string beginning with a single `$`:\n\n```php\n\u003c?php\n\nuse function Stillat\\StatamicAttributeRenderer\\attributes;\n\nattributes([\n    'name' =\u003e 'author',\n    'content' =\u003e '$author',\n    'content_two' =\u003e '$$author',\n    'content_three' =\u003e '$$$author',\n], [\n    'author' =\u003e 'John Doe'\n]);\n```\n\nwhich produces the following output:\n\n```html\nname=\"author\" content=\"John Doe\" content_two=\"$author\" content_three=\"$$author\"\n```\n\nAttribute Renderer does not support more complicated variable paths, such as nested properties, or array indices. If you need something more complicated, consider using a closure based variable resolver.\n\n## Closure Based Variable Resolvers\n\nWe can supply a `Closure` as the value of our attribute in order to resolve more complicated values. We will receive the context array as the first argument:\n\n```php\n\u003c?php\n\nuse function Stillat\\StatamicAttributeRenderer\\attributes;\n\nattributes([\n    'name' =\u003e 'author',\n    'content' =\u003e function (array $context) {\n        return 'Hello, '.$context['author'];\n    },\n], [\n    'author' =\u003e 'John Doe'\n]);\n```\n\nwhich produces:\n\n```html\nname=\"author\" content=\"Hello, John Doe\"\n```\n\n## Skippable/Ignorable Properties\n\nBy default, Attribute Renderer will emit empty strings if a value returns `null`:\n\n```php\n\u003c?php\n\nuse function Stillat\\StatamicAttributeRenderer\\attributes;\n\nattributes([\n    'name' =\u003e 'author',\n    'content' =\u003e '$name'\n]);\n```\n\nproduces:\n\n```html\nname=\"author\" content=\"\"\n```\n\nwe can let Attribute Renderer know its okay to ignore a property when producing the final result:\n\n```php\n\u003c?php\n\nuse function Stillat\\StatamicAttributeRenderer\\attributes;\nuse function Stillat\\StatamicAttributeRenderer\\isIgnorable;\n\nattributes([\n    'name' =\u003e 'author',\n    'content' =\u003e isIgnorable('$name')\n]);\n```\n\nwould now produce:\n\n```html\nname=\"author\"\n```\n\nHowever, if the value did exist within the context:\n\n```php\n\u003c?php\n\nuse function Stillat\\StatamicAttributeRenderer\\attributes;\nuse function Stillat\\StatamicAttributeRenderer\\isIgnorable;\n\nattributes([\n    'name' =\u003e 'author',\n    'content' =\u003e isIgnorable('$name')\n], [\n    'name' =\u003e 'John Doe'\n]);\n```\n\nthe ignorable property is added to the output:\n\n```html\nname=\"author\" content=\"John Doe\"\n```\n\n## Rejectable Properties\n\nRejectable properties are similar to ignorable properties. However, if a `null` or empty string value is resolved for one of these values, an empty attribute string is returned, regardless of if other property values were matched:\n\n```php\n\u003c?php\n\nuse function Stillat\\StatamicAttributeRenderer\\attributes;\nuse function Stillat\\StatamicAttributeRenderer\\rejectsOnEmpty;\n\nattributes([\n    'name' =\u003e 'author',\n    'content' =\u003e rejectsOnEmpty('$name'),\n    'first_name' =\u003e '$first_name'\n], [\n    'first_name' =\u003e 'John Doe'\n]);\n```\n\n## License\n\nAttribute Renderer is free software, released under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstillat%2Fstatamic-attribute-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstillat%2Fstatamic-attribute-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstillat%2Fstatamic-attribute-renderer/lists"}