class TagRenderer

Methods

__construct(bool $withInertiaAttributes = false)

Create the tag renderer.

withInertiaAttributes()

Get a renderer that stamps tags with data-inertia ownership attributes.

string
title(string $title, string|null $inertiaKey = null)

Render an escaped title tag.

string
meta(string $attribute, string $key, string|int|float|bool $content, string|null $inertiaKey = null)

Render a meta tag keyed by the given attribute ("name" or "property").

string
metaWithAttributes(string $attribute, string $key, array $attributes, string|null $inertiaKey = null)

Render a meta tag keyed by the given attribute ("name" or "property") with arbitrary attributes.

string
link(string $rel, string $href, string|null $inertiaKey = null)

Render a link tag.

string
linkWithAttributes(string $rel, array $attributes, string|null $inertiaKey = null)

Render a link tag with arbitrary attributes.

string
jsonLd(array $schema, string|null $inertiaKey = null)

Render structured data with script-safe JSON encoding.

string
attributes(array $attributes)

Render escaped HTML attributes.

bool
isValidAttributeName(string $name)

Attribute names aren't HTML-escaped, so reject anything that could break out of the attribute position. The "u" modifier also makes invalid UTF-8 fail the match.

string
stableKey(string $prefix, string $value)

Generate a stable, content-derived data-inertia key for a tag.

string
renderAttributes(array ...$attributeSets)

Validate and escape the combined attribute sets.

string
voidElement(string $name, array ...$attributeSets)

Render a void HTML element.

string
element(string $name, string $content, array ...$attributeSets)

Render an HTML element with content.

string
renderedAttributes(array ...$attributeSets)

Render attributes with their leading separator.

array
inertiaAttributes(string|null $key)

Get the ownership attribute when Inertia rendering is enabled.

Details

at line 14
__construct(bool $withInertiaAttributes = false)

Create the tag renderer.

Parameters

bool $withInertiaAttributes

at line 21
TagRenderer withInertiaAttributes()

Get a renderer that stamps tags with data-inertia ownership attributes.

Return Value

TagRenderer

at line 29
string title(string $title, string|null $inertiaKey = null)

Render an escaped title tag.

Parameters

string $title
string|null $inertiaKey

Return Value

string

at line 39
string meta(string $attribute, string $key, string|int|float|bool $content, string|null $inertiaKey = null)

Render a meta tag keyed by the given attribute ("name" or "property").

Parameters

string $attribute
string $key
string|int|float|bool $content
string|null $inertiaKey

Return Value

string

at line 51
string metaWithAttributes(string $attribute, string $key, array $attributes, string|null $inertiaKey = null)

Render a meta tag keyed by the given attribute ("name" or "property") with arbitrary attributes.

Parameters

string $attribute
string $key
array $attributes
string|null $inertiaKey

Return Value

string

Render a link tag.

Parameters

string $rel
string $href
string|null $inertiaKey

Return Value

string

at line 82
string linkWithAttributes(string $rel, array $attributes, string|null $inertiaKey = null)

Render a link tag with arbitrary attributes.

Parameters

string $rel
array $attributes
string|null $inertiaKey

Return Value

string

at line 99
string jsonLd(array $schema, string|null $inertiaKey = null)

Render structured data with script-safe JSON encoding.

Parameters

array $schema
string|null $inertiaKey

Return Value

string

at line 117
string attributes(array $attributes)

Render escaped HTML attributes.

Parameters

array $attributes

Return Value

string

at line 127
protected bool isValidAttributeName(string $name)

Attribute names aren't HTML-escaped, so reject anything that could break out of the attribute position. The "u" modifier also makes invalid UTF-8 fail the match.

Parameters

string $name

Return Value

bool

at line 135
string stableKey(string $prefix, string $value)

Generate a stable, content-derived data-inertia key for a tag.

Parameters

string $prefix
string $value

Return Value

string

at line 145
protected string renderAttributes(array ...$attributeSets)

Validate and escape the combined attribute sets.

Parameters

array ...$attributeSets

Return Value

string

at line 183
protected string voidElement(string $name, array ...$attributeSets)

Render a void HTML element.

Parameters

string $name
array ...$attributeSets

Return Value

string

at line 193
protected string element(string $name, string $content, array ...$attributeSets)

Render an HTML element with content.

Parameters

string $name
string $content
array ...$attributeSets

Return Value

string

at line 203
protected string renderedAttributes(array ...$attributeSets)

Render attributes with their leading separator.

Parameters

array ...$attributeSets

Return Value

string

at line 215
protected array inertiaAttributes(string|null $key)

Get the ownership attribute when Inertia rendering is enabled.

Parameters

string|null $key

Return Value

array