class Html extends Object 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
protected array $children
static bool $xhtml
static array $emptyElements

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.

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)

Adds new element's child.

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

Static factory.

Parameters

$name
$attrs

Return Value

Html

at line 85
Html setName($name, $isEmpty = NULL)

Changes element's name.

Parameters

$name
$isEmpty

Return Value

Html

Exceptions

InvalidArgumentException

at line 101
string getName()

Returns element's name.

Return Value

string

at line 111
bool isEmpty()

Is element empty?

Return Value

bool

at line 122
Html addAttributes(array $attrs)

Sets multiple attributes.

Parameters

array $attrs

Return Value

Html

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

Overloaded setter for element's attribute.

Parameters

$name
$value

Return Value

void

at line 146
mixed __get($name)

Overloaded getter for element's attribute.

Parameters

$name

Return Value

mixed

property value

at line 157
bool __isset($name)

Overloaded tester for element's attribute.

Parameters

$name

Return Value

bool

at line 168
void __unset($name)

Overloaded unsetter for element's attribute.

Parameters

$name

Return Value

void

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

Overloaded setter for element's attribute.

Parameters

$m
$args

Return Value

mixed

at line 219
Html href($path, $query = NULL)

Special setter for element's attribute.

Parameters

$path
$query

Return Value

Html

at line 236
Html data($name, $value = NULL)

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

Parameters

$name
$value

Return Value

Html

at line 253
Html setHtml($html)

Sets element's HTML content.

Parameters

$html

Return Value

Html

Exceptions

InvalidArgumentException

at line 268
string getHtml()

Returns element's HTML content.

Return Value

string

at line 288
Html setText($text)

Sets element's textual content.

Parameters

$text

Return Value

Html

Exceptions

InvalidArgumentException

at line 301
string getText()

Returns element's textual content.

Return Value

string

at line 312
Html add($child)

Adds new element's child.

Parameters

$child

Return Value

Html

at line 323
Html addHtml($child)

Adds new element's child.

Parameters

$child

Return Value

Html

at line 334
Html addText($text)

Appends plain-text string to element content.

Parameters

$text

Return Value

Html

at line 347
Html create($name, $attrs = NULL)

Creates and adds a new Html child.

Parameters

$name
$attrs

Return Value

Html

created element

at line 362
Html insert($index, $child, $replace = FALSE)

Inserts child node.

Parameters

$index
$child
$replace

Return Value

Html

Exceptions

InvalidArgumentException

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

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

Parameters

$index
$child

Return Value

void

at line 397
Html|string offsetGet($index)

Returns child node (\ArrayAccess implementation).

Parameters

$index

Return Value

Html|string

at line 408
bool offsetExists($index)

Exists child node? (\ArrayAccess implementation).

Parameters

$index

Return Value

bool

at line 419
void offsetUnset($index)

Removes child node (\ArrayAccess implementation).

Parameters

$index

Return Value

void

at line 431
int count()

Returns children count.

Return Value

int

at line 441
void removeChildren()

Removes all children.

Return Value

void

at line 451
ArrayIterator getIterator()

Iterates over elements.

Return Value

ArrayIterator

at line 461
array getChildren()

Returns all children.

Return Value

array

at line 472
string render($indent = NULL)

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

Parameters

$indent

Return Value

string

at line 500
string __toString()

No description

Return Value

string

in HTML format

at line 515
string startTag()

Returns element's start tag.

Return Value

string

at line 530
string endTag()

Returns element's end tag.

Return Value

string

at line 541
string attributes()

internal  
 

Returns element's attributes.

Return Value

string

at line 613
__clone()

Clones all children too.