This package is not maintened anymore (but still works) : Use https://github.com/PiedWeb/RenderHtmlAttribute, (*1)
Plates Extension : Render html tag attributes
, (*2)
This package is an extension for the template engine Plates., (*3)
Two features for the same goal Manipulate html tag attributes via PHP array :
* $this->attr(array $attributes)
transform an array in html tag attributes
* $this->mergeAttr(array $arr1, array $arr2, [array $arr3, ...])
merge multiple array without loosing values (Eg. : ['class' => 'main']
+ ['class' => 'content']
= ['class' => 'main content']
), (*4)
Table of contents
Usage
/* Template Init */
$templateEngine = new \League\Plates\Engine('app/views');
/* Load this extension */
$templateEngine->loadExtension(new \rOpenDev\PlatesExtension\Attributes());
$this->render('test', ['attributes' => ['class' => 'content']]);
In your app/views/test.php
template file:, (*5)
<?php
$defaultAttributes = ['class' => 'main'];
$attributes = isset($attributes) ? $this->mergeAttr($defaultAttributes, $attributes) : $defaultAttributes;
?>
<div<?=$this->attr($attributes)?>>Hello World !</div>
Will render:, (*6)
<div class="main content">Hello World !</div>
Installation
composer require ropendev/platesattributes
Requirements
Stand alone extension., (*7)
See composer.json
file., (*8)
Contributing
See CONTRIBUTING.md
file., (*9)
Contributors
License
MIT (see the LICENSE file for details), (*10)