plato-creative/silverstripe-htmltag

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

安装: 139

依赖者: 1

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 7

类型:silverstripe-vendormodule

1.1.3 2023-04-04 23:45 UTC

This package is auto-updated.

Last update: 2024-09-05 02:54:06 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>