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.

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.

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

Removed all children.

getIterator()

Iterates over a elements.

array
getChildren()

Returns all of 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 137
void __set($name, $value)

Overloaded setter for element's attribute.

Parameters

$name
$value

Return Value

void

at line 148
mixed __get($name)

Overloaded getter for element's attribute.

Parameters

$name

Return Value

mixed

property value

at line 159
bool __isset($name)

Overloaded tester for element's attribute.

Parameters

$name

Return Value

bool

at line 170
void __unset($name)

Overloaded unsetter for element's attribute.

Parameters

$name

Return Value

void

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

Overloaded setter for element's attribute.

Parameters

$m
$args

Return Value

mixed

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

Special setter for element's attribute.

Parameters

$path
$query

Return Value

Html

at line 240
Html setHtml($html)

Sets element's HTML content.

Parameters

$html

Return Value

Html

Exceptions

InvalidArgumentException

at line 255
string getHtml()

Returns element's HTML content.

Return Value

string

at line 275
Html setText($text)

Sets element's textual content.

Parameters

$text

Return Value

Html

Exceptions

InvalidArgumentException

at line 288
string getText()

Returns element's textual content.

Return Value

string

at line 299
Html add($child)

Adds new element's child.

Parameters

$child

Return Value

Html

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

Creates and adds a new Html child.

Parameters

$name
$attrs

Return Value

Html

created element

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

Inserts child node.

Parameters

$index
$child
$replace

Return Value

Html

Exceptions

InvalidArgumentException

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

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

Parameters

$index
$child

Return Value

void

at line 361
Html|string offsetGet($index)

Returns child node (\ArrayAccess implementation).

Parameters

$index

Return Value

Html|string

at line 372
bool offsetExists($index)

Exists child node? (\ArrayAccess implementation).

Parameters

$index

Return Value

bool

at line 383
void offsetUnset($index)

Removes child node (\ArrayAccess implementation).

Parameters

$index

Return Value

void

at line 395
int count()

Returns children count.

Return Value

int

at line 405
void removeChildren()

Removed all children.

Return Value

void

at line 415
ArrayIterator getIterator()

Iterates over a elements.

Return Value

ArrayIterator

at line 428
array getChildren()

Returns all of children.

Return Value

array

at line 439
string render($indent = NULL)

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

Parameters

$indent

Return Value

string

at line 467
string __toString()

No description

Return Value

string

in HTML format

at line 477
string startTag()

Returns element's start tag.

Return Value

string

at line 492
string endTag()

Returns element's end tag.

Return Value

string

at line 503
string attributes()

internal  
 

Returns element's attributes.

Return Value

string

at line 575
__clone()

Clones all children too.