plato-creative/silverstripe-htmltag

Provides a simply method for wrapping strings with html tags.

Maintainers

Package info

github.com/PlatoCreative/silverstripe-htmltag

Homepage

Type:silverstripe-vendormodule

pkg:composer/plato-creative/silverstripe-htmltag

Statistics

Installs: 151

Dependents: 1

Suggesters: 0

Stars: 0

1.1.3 2023-04-04 23:45 UTC

This package is auto-updated.

Last update: 2026-03-05 06:27:39 UTC


README

Installation

Composer is the recommended way of installing SilverStripe modules.

composer require gorriecoe/silverstripe-htmltag

Requirements

  • silverstripe/framework ^4.0

Maintainers

Template usage

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

Is the equivalent of

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

And returns

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

Controller/Object usage

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;
    }
}

Accessing and modifying the output in the template

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