https://github.com/timkelty/htmlattributes-craft
HTML Attributes Twig filter for Craft CMS
https://github.com/timkelty/htmlattributes-craft
Last synced: 10 months ago
JSON representation
HTML Attributes Twig filter for Craft CMS
- Host: GitHub
- URL: https://github.com/timkelty/htmlattributes-craft
- Owner: timkelty
- License: mit
- Created: 2014-12-01T21:11:00.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-12-03T21:54:30.000Z (over 11 years ago)
- Last Synced: 2025-08-09T08:19:31.028Z (10 months ago)
- Language: PHP
- Size: 141 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# htmlAttributes
A Craft plugin (Twig filter) to help with the output of HTML attributes.
## Usage
### Twig template
```
{% set attrs = {
class: ['myClass', 'myClass2'],
style: {
'background-image': "url('img.png')",
'color': 'red',
},
'data-foo': {
someKey: 'foo',
otherKey: 'bar',
myArray: ['foo', 'bar', 'baz'],
},
'data-bar': true,
'data-baz': null,
'data-qux': false,
} %}
```
`htmlAttributes` is also aliased to `htmlAttrs` for convenince.
### Output
```
```