gorriecoe/silverstripe-htmltag

提供了一种简单的方法来包装字符串的HTML标签。

安装次数: 11,434

依赖者: 3

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 7

开放问题: 1

类型:silverstripe-vendormodule

1.1.2 2018-04-12 08:50 UTC

This package is auto-updated.

Last update: 2024-08-29 04:37:42 UTC


README

安装

Composer是安装SilverStripe模块的推荐方式。

composer require gorriecoe/silverstripe-htmltag

要求

  • silverstripe/framework ^4.0

维护者

模板使用

{$h1($Title).setClass('title').setPrefix($Class)}

等同于

<% if Title %>
    <h1 class="{$class}__title title">
        {$Title}
    </h1>
<% end_if %>

并返回

<h1 class="title content-section__title">
    This sections title
</h1>

控制器/对象使用

use gorriecoe\HTMLTag\View\HTMLTag;

class MyController extends Controller
{
    public function Title()
    {
        $title = HTMLTag::create($this->Data()->Title, 'h1')
            ->setPrefix($this->Class);
        if (true) {
            $title->setClass('title')
        }
        return $title;
    }
}

在模板中访问和修改输出

<div>
    {$Title.addClass('anotherclass')}
</div>