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',
];

Properties

protected array $attributes

List of attributes to render on the frontend

Methods

public
$this
setAttribute($name, $value)

Set an HTML attribute

public
mixed|null
getAttribute(string $name)

Retrieve the value of an HTML attribute

protected
array
getDefaultAttributes()

Get the default attributes when rendering this object.

public
array
getAttributes()

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

public
string
getAttributesHTML(array $attributes = null)

Custom attributes to process. Falls back to 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

abstract protected array getDefaultAttributes()

Get the default attributes when rendering this object.

Called by getAttributes()

Return Value

array

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 getAttributes().

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

Parameters

array $attributes

Return Value

string