Class Html (namespace Nette\Web)


HTML helper.

  1. 1:  $anchor Html::el('a')->href($link)->setText('Nette');
  2. 2:  $el->class 'myclass';
  3. 3:  echo $el;
  4. 4:  
  5. 5:  echo $el->startTag()$el->endTag();

Object
   |
   --Html

Implements interfaces:

ArrayAccess (internal interface), Countable (internal interface), IteratorAggregate (internal interface)
Author: David Grudl
Copyright: Copyright (c) 2004, 2009 David Grudl
Located: in /Web/Html.php (line 42)
Public Method Summary
Html
add (Html|string $child)
Adds new element's child.
string
Returns element's attributes.
int
count ()
Required by the \Countable interface.
Html
create (string $name, [array|string $attrs = NULL])
Creates and adds a new Html child.
static Html
el ([string $name = NULL], [array|string $attrs = NULL])
Static factory.
string
endTag ()
Returns element's end tag.
void
Returns all of children.
RecursiveIterator
getIterator ([bool $deep = FALSE], string 1)
Iterates over a elements.
string
getName ()
Returns element's name.
string
getText ()
Gets element's textual content.
Html
href (string $path, [array $query = NULL])
Special setter for element's attribute.
Html
insert (int $index, Html $child, [bool $replace = FALSE])
Inserts child node.
bool
isEmpty ()
Is element empty?
bool
offsetExists (int $index)
Exists child node? (\ArrayAccess implementation).
mixed
offsetGet (int $index)
Returns child node (\ArrayAccess implementation).
void
offsetSet (int $index, Html $child)
Inserts (replaces) child node (\ArrayAccess implementation).
void
offsetUnset (int $index)
Removes child node (\ArrayAccess implementation).
void
Removed all children.
string
render ([int $indent = NULL])
Renders element's start tag, content and end tag.
Html
setHtml (string $html)
Sets element's HTML content.
Html
setName (string $name, [bool $isEmpty = NULL])
Changes element's name.
Html
setText (string $text, [$isHtml = FALSE])
Sets element's textual content.
string
Returns element's start tag.
Html
__call (string $m, array $args)
Overloaded setter for element's attribute.
void
__clone ()
Clones all children too.
& mixed
__get (string $name)
Overloaded getter for element's attribute.
void
__set (string $name, mixed $value)
Overloaded setter for element's attribute.
void
void
__unset (string $name)
Overloaded unsetter for element's attribute.
Methods Inherited From Object
extensionMethod(), getClass(), getReflection(), __call(), __callStatic(), __get(), __isset(), __set(), __unset()
Variable Summary
array $attrs array()

line 51

element's attributes
protected array $children array()

line 54

of Html | string nodes
static array $emptyElements array('img'=>1,'hr'=>1,'br'=>1,'input'=>1,'meta'=>1,'area'=>1,...

line 60

empty elements
static bool $xhtml TRUE

line 57

use XHTML syntax?

Method Details

line 280

add

public Html add (Html|string $child)

Adds new element's child.

Input
Html|string $child child node
Output
Html provides a fluent interface

line 505

attributes

public string attributes ()

Returns element's attributes.

Output
string  

line 383

count

public int count ()

Required by the \Countable interface.

Implementation of:

Countable::count
Output
int  

line 293

create

public Html create (string $name, [array|string $attrs = NULL])

Creates and adds a new Html child.

Input
string $name elements's name
array|string $attrs element's attributes (or textual content)
Output
Html created element

line 71

el

public static Html el ([string $name = NULL], [array|string $attrs = NULL])

Static factory.

Input
string $name element name (or NULL)
array|string $attrs element's attributes (or textual content)
Output
Html  

line 494

endTag

public string endTag ()

Returns element's end tag.

Output
string  

line 424

getChildren

public void getChildren ()

Returns all of children.

return array

Output
void  

line 407

getIterator

public RecursiveIterator getIterator ([bool $deep = FALSE], string 1)

Iterates over a elements.

Implementation of:

IteratorAggregate::getIterator
Input
bool $deep recursive?
string 1 class types filter
Output
RecursiveIterator  

line 116

getName

public string getName ()

Returns element's name.

Output
string  

line 263

getText

public string getText ()

Gets element's textual content.

Output
string  

line 203

href

public Html href (string $path, [array $query = NULL])

Special setter for element's attribute.

Input
string $path path
array $query query
Output
Html provides a fluent interface

line 309

insert

public Html insert (int $index, Html $child, [bool $replace = FALSE])

Inserts child node.

Input
int $index
Html $child node
bool $replace
Output
Html provides a fluent interface
Throws
throws Exception

line 127

isEmpty

public bool isEmpty ()

Is element empty?

Output
bool  

line 358

offsetExists

public bool offsetExists (int $index)

Exists child node? (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetExists
Input
int $index index
Output
bool  

line 346

offsetGet

public mixed offsetGet (int $index)

Returns child node (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetGet
Input
int $index index
Output
mixed  

line 334

offsetSet

public void offsetSet (int $index, Html $child)

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

Implementation of:

ArrayAccess::offsetSet
Input
int $index
Html $child node
Output
void  

line 370

offsetUnset

public void offsetUnset (int $index)

Removes child node (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetUnset
Input
int $index index
Output
void  

line 394

removeChildren

public void removeChildren ()

Removed all children.

Output
void  

line 436

render

public string render ([int $indent = NULL])

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

Input
int $indent indent
Output
string  

line 221

setHtml

public Html setHtml (string $html)

Sets element's HTML content.

Input
string $html
Output
Html provides a fluent interface
Throws
throws InvalidArgumentException

line 99

setName

public Html setName (string $name, [bool $isEmpty = NULL])

Changes element's name.

Input
string $name
bool $isEmpty Is element empty?
Output
Html provides a fluent interface
Throws
throws InvalidArgumentException

line 246

setText

public Html setText (string $text, [$isHtml = FALSE])

Sets element's textual content.

Input
string $text
$isHtml
Output
Html provides a fluent interface
Throws
throws InvalidArgumentException

line 478

startTag

public string startTag ()

Returns element's start tag.

Output
string  

line 177

__call

public Html __call (string $m, array $args)

Overloaded setter for element's attribute.

Input
string $m HTML attribute name
array $args (string) HTML attribute value or pair?
Output
Html provides a fluent interface

line 557

__clone

public void __clone ()

Clones all children too.

Output
void  

line 152

__get

public mixed & __get (string $name)

Overloaded getter for element's attribute.

Input
string $name HTML attribute name
Output
& mixed HTML attribute value

line 140

__set

public void __set (string $name, mixed $value)

Overloaded setter for element's attribute.

Input
string $name HTML attribute name
mixed $value HTML attribute value
Output
void  

line 467

__toString

public void __toString ()

Output
void  

line 164

__unset

public void __unset (string $name)

Overloaded unsetter for element's attribute.

Input
string $name HTML attribute name
Output
void