trait AttributesHTML (View source)

This trait can be applied to a ViewableData class to add the logic to render attributes in an SS template.

When applying this trait to a class, you also need to add the following casting configuration.

private static $casting = [
    'AttributesHTML' => 'HTMLFragment',
    'getAttributesHTML' => 'HTMLFragment',
];

Methods

$this
setAttribute($name, $value)

Set an HTML attribute

mixed|null
getAttribute(string $name)

Retrieve the value of an HTML attribute

array
getAttributes()

Allows customization through an 'updateAttributes' hook on the base class.

string
getAttributesHTML(array $attributes = null)

Custom attributes to process. Falls back to {@link getAttributes()}.

Details

$this setAttribute($name, $value)

Set an HTML attribute

Parameters

$name
$value

Return Value

$this

mixed|null getAttribute(string $name)

Retrieve the value of an HTML attribute

Parameters

string $name

Return Value

mixed|null

array getAttributes()

Allows customization through an 'updateAttributes' hook on the base class.

Existing attributes are passed in as the first argument and can be manipulated, but any attributes added through a subclass implementation won't be included.

Return Value

array

string getAttributesHTML(array $attributes = null)

Custom attributes to process. Falls back to {@link getAttributes()}.

If at least one argument is passed as a string, all arguments act as excludes, by name.

Parameters

array $attributes

Return Value

string