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)
Copyright: Copyright (c) 2004, 2010 David Grudl
Located: in /Web/Html.php (line 29)
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.
string
getHtml ()
Returns element's HTML content.
RecursiveIterator
getIterator ([bool $deep = FALSE], string 1)
Iterates over a elements.
string
getName ()
Returns element's name.
string
getText ()
Returns 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)
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 38

element's attributes
protected array $children array()

line 41

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

line 47

empty elements
static bool $xhtml TRUE

line 44

use XHTML syntax?

Method Details

line 294

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 517

attributes

public string attributes ()

Returns element's attributes.

Output
string  

line 397

count

public int count ()

Required by the \Countable interface.

Implementation of:

Countable::count
Output
int  

line 307

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 58

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 506

endTag

public string endTag ()

Returns element's end tag.

Output
string  

line 438

getChildren

public void getChildren ()

Returns all of children.

return array

Output
void  

line 247

getHtml

public string getHtml ()

Returns element's HTML content.

Output
string  

line 421

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 107

getName

public string getName ()

Returns element's name.

Output
string  

line 282

getText

public string getText ()

Returns element's textual content.

Output
string  

line 206

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 323

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 118

isEmpty

public bool isEmpty ()

Is element empty?

Output
bool  

line 372

offsetExists

public bool offsetExists (int $index)

Exists child node? (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetExists
Input
int $index index
Output
bool  

line 360

offsetGet

public mixed offsetGet (int $index)

Returns child node (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetGet
Input
int $index index
Output
mixed  

line 348

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 384

offsetUnset

public void offsetUnset (int $index)

Removes child node (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetUnset
Input
int $index index
Output
void  

line 408

removeChildren

public void removeChildren ()

Removed all children.

Output
void  

line 450

render

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

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

Input
int $indent indent
Output
string  

line 224

setHtml

public Html setHtml (string $html)

Sets element's HTML content.

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

line 90

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 268

setText

public Html setText (string $text)

Sets element's textual content.

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

line 490

startTag

public string startTag ()

Returns element's start tag.

Output
string  

line 168

__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 569

__clone

public void __clone ()

Clones all children too.

Output
void  

line 143

__get

public mixed & __get (string $name)

Overloaded getter for element's attribute.

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

line 131

__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 479

__toString

public void __toString ()

Output
void  

line 155

__unset

public void __unset (string $name)

Overloaded unsetter for element's attribute.

Input
string $name HTML attribute name
Output
void