[Plates Extension] Permits to transform an array in html tag attributes
Switch branches/tags
Nothing to show
Clone or download
RobinDev BugFixes: Correct escaping for attributes...
... and minor optimization.
Latest commit c85b6ab Jan 13, 2015

README.md

Plates Extension : Render html tag attributes

Quality Score SensioLabsInsight Build Status

This package is an extension for the template engine Plates.

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'])

##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:

<?php
$defaultAttributes = ['class' => 'main'];
$attributes        = isset($attributes) ? $this->mergeAttr($defaultAttributes, $attributes) : $defaultAttributes;
?>
<div<?=$this->attr($attributes)?>>Hello World !</div>

Will render:

<div class="main content">Hello World !</div>

Installation

composer require ropendev/platesattributes

Requirements

Stand alone extension.

See composer.json file.

Contributing

See CONTRIBUTING.md file.

Contributors

License

MIT (see the LICENSE file for details)