https://github.com/piedweb/renderhtmlattribute
[PHP] Twig Extension to render html attributes
https://github.com/piedweb/renderhtmlattribute
Last synced: 12 months ago
JSON representation
[PHP] Twig Extension to render html attributes
- Host: GitHub
- URL: https://github.com/piedweb/renderhtmlattribute
- Owner: PiedWeb
- Created: 2018-11-12T09:18:34.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2025-03-05T10:29:04.000Z (over 1 year ago)
- Last Synced: 2025-04-20T18:20:40.711Z (about 1 year ago)
- Language: PHP
- Homepage: https://dev.piedweb.com/
- Size: 32.2 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Twig Extension : Render html tag attributes
[](https://github.com/PiedWeb/RenderHtmlAttribute/tags)
[](LICENSE)
[](https://codecov.io/gh/PiedWeb/PiedWeb/branch/main)
[](https://shepherd.dev/github/PiedWeb/PiedWeb)
[](https://packagist.org/packages/piedweb/render-html-attributes)
This package is an extension for both [Twig](https://github.com/twigphp/Twig) and ~Plate engine [Plates](https://github.com/thephpleague/plates)~.
Plates is not anymore supported since v1.0.3.
Two features for the same goal **Manipulate html tag attributes via object/PHP array** :
- `attr({class: "col", id: "piedweb", data-content:"Hello :)', ...})` transform an array in html tag attributes
- `mergeAttr($attributes1, $attributes2, [$attributes3, ...])` merge multiple array without loosing values (Eg. : `['class' => 'main']` + `['class' => 'content']` = `['class' => 'main content']`)
## Table of contents
- [Twig Extension : Render html tag attributes](#twig-extension--render-html-tag-attributes)
- [Table of contents](#table-of-contents)
- [Usage](#usage)
- [Installation](#installation)
- [Requirements](#requirements)
- [Contributors](#contributors)
- [License](#license)
## Usage
Load the extension in twig (eg for symfony) :
```
piedweb.twig.extension.render_attributes:
class: PiedWeb\RenderAttributes\TwigExtension
public: false
tags:
- { name: twig.extension }
```
Then use it :
```
{{ attr({class:"main content"})|raw }}
{{ mergeAttr({class:"main"}, {class:"content"})|raw }}
```
## Installation
```bash
composer require piedweb/render-html-attributes
```
## Requirements
Stand alone extension.
See `composer.json` file.
## Contributors
- Original author [Robin (PiedWeb from the Alps Mountain)](https://piedweb.com)
- ...
## License
MIT (see the LICENSE file for details)