BaseHtml
API reference › HTML Core › Base › BaseHtml
1 subclass
Provides the base implementation for rendering HTML tags.
See also: https://developer.mozilla.org/en-US/docs/Glossary/Block-level_content, https://developer.mozilla.org/en-US/docs/Glossary/Inline-level_content, https://developer.mozilla.org/en-US/docs/Glossary/Void_element, https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements#main_root, https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements#table_content.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
begin() static | Returns the opening tag for a block element. | BaseHtml |
element() static | Returns a complete HTML element string. | BaseHtml |
end() static | Returns the closing tag for a block element. | BaseHtml |
inline() static | Returns an inline HTML element string. | BaseHtml |
void() static | Returns a void HTML element string. | BaseHtml |
Method details
Section titled “Method details”begin()
Section titled “begin() ”public static function begin(BackedEnum $tag, array $attributes = []): stringReturns the opening tag for a block element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tag | BackedEnum | Tag enumeration instance. |
$attributes | array | Associative array of HTML attributes. |
Returns
string: Rendered opening tag string with attributes. The pre and textarea opening tags do not add a newline. Callers must supply a protective LF before streamed content starting with LF or CR (including CRLF); the opening tag cannot inspect future content. Block for valid block-level tags. Lists for valid list-level tags. Root for valid root-level tags. Table for valid table-level tags.
element()
Section titled “element() ”public static function element(BackedEnum $tag, string $content, array $attributes = [], bool $encode = false): stringReturns a complete HTML element string.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tag | BackedEnum | Tag enumeration instance. |
$content | string | Content to be rendered inside the tag. |
$attributes | array | Associative array of HTML attributes. |
$encode | bool | Whether to encode the content for HTML output. |
Returns
string: Rendered HTML element string. The pre and textarea elements do not receive presentation newlines around nonempty content. A protective LF is added only when their content starts with LF or CR (including CRLF). HTML normalizes CR/CRLF to LF before ignoring the first newline; the supplied content bytes are not normalized here. Block for valid block-level tags. Inline for valid inline-level tags. Lists for valid list-level tags. Root for valid root-level tags. Table for valid table-level tags. For void tags, use Html::void().
end()
Section titled “end() ”public static function end(BackedEnum $tag): stringReturns the closing tag for a block element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tag | BackedEnum | Tag enumeration instance. |
Returns
string: Rendered closing tag string. No presentation newline is added before pre or textarea closing tags, so streamed content stays intact. Block for valid block-level tags. Lists for valid list-level tags. Root for valid root-level tags. Table for valid table-level tags.
inline()
Section titled “inline() ”public static function inline(BackedEnum $tag, string $content, array $attributes = [], bool $encode = false): stringReturns an inline HTML element string.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tag | BackedEnum | Inline tag enumeration instance. |
$content | string | Content to be rendered inside the tag. |
$attributes | array | Associative array of HTML attributes. |
$encode | bool | Whether to encode the content for HTML output. |
Returns
string: Rendered inline HTML element string. Inline for valid inline-level tags.
void()
Section titled “void() ”public static function void(BackedEnum $tag, array $attributes = []): stringReturns a void HTML element string.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tag | BackedEnum | Void tag enumeration instance. |
$attributes | array | Associative array of HTML attributes. |
Returns
string: Rendered void HTML element string. Voids for valid void-level tags.