class Html implements ArrayAccess, Countable, IteratorAggregate, IHtmlString

HTML helper.

$el = Html::el('a')->href($link)->setText('Nette'); $el->class = 'myclass'; echo $el;

echo $el->startTag(), $el->endTag();

Traits

Strict class for better experience.

Properties

array $attrs
static bool $xhtml
static array $emptyElements
protected array $children

Methods

static Html
el(string $name = null, $attrs = null)

Static factory.

setName(string $name, bool $isEmpty = null)

Changes element's name.

string
getName()

Returns element's name.

bool
isEmpty()

Is element empty?

addAttributes(array $attrs)

Sets multiple attributes.

appendAttribute(string $name, $value, $option = true)

Appends value to element's attribute.

setAttribute(string $name, $value)

Sets element's attribute.

mixed
getAttribute(string $name)

Returns element's attribute.

removeAttribute(string $name)

Unsets element's attribute.

removeAttributes(array $attributes)

Unsets element's attributes.

void
__set(string $name, $value)

Overloaded setter for element's attribute.

mixed
__get(string $name)

Overloaded getter for element's attribute.

bool
__isset(string $name)

Overloaded tester for element's attribute.

void
__unset(string $name)

Overloaded unsetter for element's attribute.

mixed
__call(string $m, array $args)

Overloaded setter for element's attribute.

href(string $path, array $query = null)

Special setter for element's attribute.

data(string $name, $value = null)

Setter for data-* attributes. Booleans are converted to 'true' resp. 'false'.

setHtml(IHtmlString|string $html)

Sets element's HTML content.

string
getHtml()

Returns element's HTML content.

setText(IHtmlString|string|int|float $text)

Sets element's textual content.

string
getText()

Returns element's textual content.

addHtml(IHtmlString|string $child)

Adds new element's child.

addText(IHtmlString|string|int|float $text)

Appends plain-text string to element content.

create(string $name, $attrs = null)

Creates and adds a new Html child.

insert(int $index = null, $child, bool $replace = false)

Inserts child node.

void
offsetSet(int|null $index, Html|string $child)

Inserts (replaces) child node (\ArrayAccess implementation).

Html|string
offsetGet(int $index)

Returns child node (\ArrayAccess implementation).

bool
offsetExists(int $index)

Exists child node? (\ArrayAccess implementation).

void
offsetUnset(int $index)

Removes child node (\ArrayAccess implementation).

int
count()

Returns children count.

void
removeChildren()

Removes all children.

getIterator()

Iterates over elements.

array
getChildren()

Returns all children.

string
render(int $indent = null)

Renders element's start tag, content and end tag.

string
__toString()

Returns string in HTML format

string
startTag()

Returns element's start tag.

string
endTag()

Returns element's end tag.

string
attributes()

Returns element's attributes.

__clone()

Clones all children too.

Details

at line 59
static Html el(string $name = null, $attrs = null)

Static factory.

Parameters

string $name
$attrs

Return Value

Html

at line 86
final Html setName(string $name, bool $isEmpty = null)

Changes element's name.

Parameters

string $name
bool $isEmpty

Return Value

Html

at line 97
final string getName()

Returns element's name.

Return Value

string

at line 106
final bool isEmpty()

Is element empty?

Return Value

bool

at line 116
Html addAttributes(array $attrs)

Sets multiple attributes.

Parameters

array $attrs

Return Value

Html

at line 127
Html appendAttribute(string $name, $value, $option = true)

Appends value to element's attribute.

Parameters

string $name
$value
$option

Return Value

Html

at line 150
Html setAttribute(string $name, $value)

Sets element's attribute.

Parameters

string $name
$value

Return Value

Html

at line 161
mixed getAttribute(string $name)

Returns element's attribute.

Parameters

string $name

Return Value

mixed

at line 171
Html removeAttribute(string $name)

Unsets element's attribute.

Parameters

string $name

Return Value

Html

at line 182
Html removeAttributes(array $attributes)

Unsets element's attributes.

Parameters

array $attributes

Return Value

Html

at line 194
final void __set(string $name, $value)

Overloaded setter for element's attribute.

Parameters

string $name
$value

Return Value

void

at line 204
final mixed __get(string $name)

Overloaded getter for element's attribute.

Parameters

string $name

Return Value

mixed

at line 213
final bool __isset(string $name)

Overloaded tester for element's attribute.

Parameters

string $name

Return Value

bool

at line 222
final void __unset(string $name)

Overloaded unsetter for element's attribute.

Parameters

string $name

Return Value

void

at line 232
final mixed __call(string $m, array $args)

Overloaded setter for element's attribute.

Parameters

string $m
array $args

Return Value

mixed

at line 263
final Html href(string $path, array $query = null)

Special setter for element's attribute.

Parameters

string $path
array $query

Return Value

Html

at line 280
Html data(string $name, $value = null)

Setter for data-* attributes. Booleans are converted to 'true' resp. 'false'.

Parameters

string $name
$value

Return Value

Html

at line 296
final Html setHtml(IHtmlString|string $html)

Sets element's HTML content.

Parameters

IHtmlString|string $html

Return Value

Html

at line 306
final string getHtml()

Returns element's HTML content.

Return Value

string

at line 317
final Html setText(IHtmlString|string|int|float $text)

Sets element's textual content.

Parameters

IHtmlString|string|int|float $text

Return Value

Html

at line 330
final string getText()

Returns element's textual content.

Return Value

string

at line 341
final Html addHtml(IHtmlString|string $child)

Adds new element's child.

Parameters

IHtmlString|string $child Html node or raw HTML string

Return Value

Html

at line 352
Html addText(IHtmlString|string|int|float $text)

Appends plain-text string to element content.

Parameters

IHtmlString|string|int|float $text

Return Value

Html

at line 366
final Html create(string $name, $attrs = null)

Creates and adds a new Html child.

Parameters

string $name
$attrs

Return Value

Html created element

at line 378
Html insert(int $index = null, $child, bool $replace = false)

Inserts child node.

Parameters

int $index
$child
bool $replace

Return Value

Html

at line 397
final void offsetSet(int|null $index, Html|string $child)

Inserts (replaces) child node (\ArrayAccess implementation).

Parameters

int|null $index position or null for appending
Html|string $child Html node or raw HTML string

Return Value

void

at line 408
final Html|string offsetGet(int $index)

Returns child node (\ArrayAccess implementation).

Parameters

int $index

Return Value

Html|string

at line 418
final bool offsetExists(int $index)

Exists child node? (\ArrayAccess implementation).

Parameters

int $index

Return Value

bool

at line 428
void offsetUnset(int $index)

Removes child node (\ArrayAccess implementation).

Parameters

int $index

Return Value

void

at line 439
final int count()

Returns children count.

Return Value

int

at line 448
void removeChildren()

Removes all children.

Return Value

void

at line 457
final ArrayIterator getIterator()

Iterates over elements.

Return Value

ArrayIterator

at line 466
final array getChildren()

Returns all children.

Return Value

array

at line 475
final string render(int $indent = null)

Renders element's start tag, content and end tag.

Parameters

int $indent

Return Value

string

at line 503
final string __toString()

Returns string in HTML format

Return Value

string

at line 516
final string startTag()

Returns element's start tag.

Return Value

string

at line 530
final string endTag()

Returns element's end tag.

Return Value

string

at line 540
final string attributes()

Returns element's attributes.

Return Value

string

at line 605
__clone()

Clones all children too.