HasContent
API reference › HTML Mixin › HasContent
Provides an immutable API for managing element content.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$content protected | string | Content string assigned to the element. Default: ''. | HasContent |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
clearContent() | Clears encoded and raw content without changing other component state. | HasContent |
content() | Appends encoded content. | HasContent |
getContent() | Returns the content assigned to the element. | HasContent |
html() | Appends trusted raw HTML content without encoding or sanitizing it. | HasContent |
Method details
Section titled “Method details”clearContent()
Section titled “clearContent() ”public function clearContent(): staticClears encoded and raw content without changing other component state.
Returns
static: New instance with empty content.
content()
Section titled “content() ”public function content(string|Stringable|UnitEnum ...$values): staticAppends encoded content.
Backed enums use their value (including 0); pure enums use their name. Values are normalized before encoding.
Parameters
| Parameter | Type | Description |
|---|---|---|
...$values | string|Stringable|UnitEnum | Content to be encoded and appended. |
Returns
static: New instance with appended encoded content.
getContent()
Section titled “getContent() ”public function getContent(): stringReturns the content assigned to the element.
Returns
string: Content value assigned to the element. Never null.
html()
Section titled “html() ”public function html(string|Stringable|UnitEnum ...$values): staticAppends trusted raw HTML content without encoding or sanitizing it.
Backed enums use their value (including 0); pure enums use their name.
Parameters
| Parameter | Type | Description |
|---|---|---|
...$values | string|Stringable|UnitEnum | Trusted raw HTML content to be appended. |
Returns
static: New instance with appended raw HTML content.