ropendev/platesattributes

[Plates 扩展] 将数组转换为 HTML 标签属性。

1.0.1 2015-01-13 10:25 UTC

This package is auto-updated.

Last update: 2024-09-12 22:07:20 UTC


README

此包不再维护(但仍可正常工作):使用https://github.com/PiedWeb/RenderHtmlAttribute

Plates 扩展:渲染 HTML 标签属性

Quality Score SensioLabsInsight Build Status

此包是模板引擎Plates的扩展。

为同一目标提供两个特性 通过 PHP 数组操作 HTML 标签属性

  • $this->attr(array $attributes) 将数组转换为 HTML 标签属性
  • $this->mergeAttr(array $arr1, array $arr2, [array $arr3, ...]) 合并多个数组而不丢失值(例如:['class' => 'main'] + ['class' => 'content'] = ['class' => 'main content']

## 目录表

## 使用方法

/* Template Init */
$templateEngine = new \League\Plates\Engine('app/views');

/* Load this extension */
$templateEngine->loadExtension(new \rOpenDev\PlatesExtension\Attributes());

$this->render('test', ['attributes' => ['class' => 'content']]);

在你的 app/views/test.php 模板文件中

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

将渲染

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

安装

composer require ropendev/platesattributes

要求

独立扩展。

请参阅 composer.json 文件。

贡献

请参阅 CONTRIBUTING.md 文件。

贡献者

许可证

MIT(有关详细信息,请参阅 LICENSE 文件)