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();

Properties

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

Methods

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

Static factory.

setName($name, $isEmpty = null)

Changes element's name.

string
getName()

Returns element's name.

bool
isEmpty()

Is element empty?

addAttributes(array $attrs)

Sets multiple attributes.

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

Appends value to element's attribute.

setAttribute($name, $value)

Sets element's attribute.

mixed
getAttribute($name)

Returns element's attribute.

removeAttribute($name)

Unsets element's attribute.

removeAttributes(array $attributes)

Unsets element's attributes.

void
__set($name, $value)

Overloaded setter for element's attribute.

mixed
__get($name)

Overloaded getter for element's attribute.

bool
__isset($name)

Overloaded tester for element's attribute.

void
__unset($name)

Overloaded unsetter for element's attribute.

mixed
__call($m, $args)

Overloaded setter for element's attribute.

href($path, $query = null)

Special setter for element's attribute.

data($name, $value = null)

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

setHtml($html)

Sets element's HTML content.

string
getHtml()

Returns element's HTML content.

setText($text)

Sets element's textual content.

string
getText()

Returns element's textual content.

add($child) deprecated

No description

addHtml($child)

Adds new element's child.

addText($text)

Appends plain-text string to element content.

create($name, $attrs = null)

Creates and adds a new Html child.

insert($index, $child, $replace = false)

Inserts child node.

void
offsetSet($index, $child)

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

Html|string
offsetGet($index)

Returns child node (\ArrayAccess implementation).

bool
offsetExists($index)

Exists child node? (\ArrayAccess implementation).

void
offsetUnset($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($indent = null)

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

string
__toString()

No description

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 57
static Html el($name = null, $attrs = null)

Static factory.

Parameters

$name
$attrs

Return Value

Html

at line 87
Html setName($name, $isEmpty = null)

Changes element's name.

Parameters

$name
$isEmpty

Return Value

Html

Exceptions

InvalidArgumentException

at line 103
string getName()

Returns element's name.

Return Value

string

at line 113
bool isEmpty()

Is element empty?

Return Value

bool

at line 124
Html addAttributes(array $attrs)

Sets multiple attributes.

Parameters

array $attrs

Return Value

Html

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

Appends value to element's attribute.

Parameters

$name
$value
$option

Return Value

Html

at line 163
Html setAttribute($name, $value)

Sets element's attribute.

Parameters

$name
$value

Return Value

Html

at line 175
mixed getAttribute($name)

Returns element's attribute.

Parameters

$name

Return Value

mixed

at line 186
Html removeAttribute($name)

Unsets element's attribute.

Parameters

$name

Return Value

Html

at line 197
Html removeAttributes(array $attributes)

Unsets element's attributes.

Parameters

array $attributes

Return Value

Html

at line 212
void __set($name, $value)

Overloaded setter for element's attribute.

Parameters

$name
$value

Return Value

void

at line 223
mixed __get($name)

Overloaded getter for element's attribute.

Parameters

$name

Return Value

mixed

HTML attribute value

at line 234
bool __isset($name)

Overloaded tester for element's attribute.

Parameters

$name

Return Value

bool

at line 245
void __unset($name)

Overloaded unsetter for element's attribute.

Parameters

$name

Return Value

void

at line 257
mixed __call($m, $args)

Overloaded setter for element's attribute.

Parameters

$m
$args

Return Value

mixed

at line 290
Html href($path, $query = null)

Special setter for element's attribute.

Parameters

$path
$query

Return Value

Html

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

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

Parameters

$name
$value

Return Value

Html

at line 324
Html setHtml($html)

Sets element's HTML content.

Parameters

$html

Return Value

Html

Exceptions

InvalidArgumentException

at line 339
string getHtml()

Returns element's HTML content.

Return Value

string

at line 350
Html setText($text)

Sets element's textual content.

Parameters

$text

Return Value

Html

at line 363
string getText()

Returns element's textual content.

Return Value

string

at line 372
add($child) deprecated

deprecated

No description

Parameters

$child

at line 384
Html addHtml($child)

Adds new element's child.

Parameters

$child

Return Value

Html

at line 395
Html addText($text)

Appends plain-text string to element content.

Parameters

$text

Return Value

Html

at line 410
Html create($name, $attrs = null)

Creates and adds a new Html child.

Parameters

$name
$attrs

Return Value

Html

created element

at line 425
Html insert($index, $child, $replace = false)

Inserts child node.

Parameters

$index
$child
$replace

Return Value

Html

Exceptions

InvalidArgumentException

at line 450
void offsetSet($index, $child)

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

Parameters

$index
$child

Return Value

void

at line 461
Html|string offsetGet($index)

Returns child node (\ArrayAccess implementation).

Parameters

$index

Return Value

Html|string

at line 472
bool offsetExists($index)

Exists child node? (\ArrayAccess implementation).

Parameters

$index

Return Value

bool

at line 483
void offsetUnset($index)

Removes child node (\ArrayAccess implementation).

Parameters

$index

Return Value

void

at line 495
int count()

Returns children count.

Return Value

int

at line 505
void removeChildren()

Removes all children.

Return Value

void

at line 515
ArrayIterator getIterator()

Iterates over elements.

Return Value

ArrayIterator

at line 525
array getChildren()

Returns all children.

Return Value

array

at line 536
string render($indent = null)

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

Parameters

$indent

Return Value

string

at line 564
string __toString()

No description

Return Value

string

in HTML format

at line 579
string startTag()

Returns element's start tag.

Return Value

string

at line 594
string endTag()

Returns element's end tag.

Return Value

string

at line 605
string attributes()

internal  
 

Returns element's attributes.

Return Value

string

at line 678
__clone()

Clones all children too.

Traits

Strict class for better experience.