An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Twig Extension : Render html tag attributes

[![Latest Version](https://img.shields.io/github/tag/PiedWeb/RenderHtmlAttribute.svg?style=flat&label=release)](https://github.com/PiedWeb/RenderHtmlAttribute/tags)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE)
[![Code Coverage](https://codecov.io/gh/PiedWeb/PiedWeb/branch/main/graph/badge.svg)](https://codecov.io/gh/PiedWeb/PiedWeb/branch/main)
[![Type Coverage](https://shepherd.dev/github/PiedWeb/PiedWeb/coverage.svg)](https://shepherd.dev/github/PiedWeb/PiedWeb)
[![Total Downloads](https://img.shields.io/packagist/dt/piedweb/render-html-attributes.svg?style=flat)](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)


Open Source Package