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 41)
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 ()
Gets element's textual content.
RecursiveIterator
getIterator ([bool $deep = FALSE], string 1)
Iterates over a elements.
string
getName ()
Returns element's name.
void
getText ()
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 50

element's attributes
protected array $children array()

line 53

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

line 59

empty elements
static bool $xhtml TRUE

line 56

use XHTML syntax?

Method Details

line 302

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 527

attributes

public string attributes ()

Returns element's attributes.

Output
string  

line 405

count

public int count ()

Required by the \Countable interface.

Implementation of:

Countable::count
Output
int  

line 315

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 70

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 516

endTag

public string endTag ()

Returns element's end tag.

Output
string  

line 446

getChildren

public void getChildren ()

Returns all of children.

return array

Output
void  

line 259

getHtml

public string getHtml ()

Gets element's textual content.

Output
string  

line 429

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 119

getName

public string getName ()

Returns element's name.

Output
string  

line 290

getText

public void getText ()

Output
void  
Tags
Deprecated

line 218

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 331

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 130

isEmpty

public bool isEmpty ()

Is element empty?

Output
bool  

line 380

offsetExists

public bool offsetExists (int $index)

Exists child node? (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetExists
Input
int $index index
Output
bool  

line 368

offsetGet

public mixed offsetGet (int $index)

Returns child node (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetGet
Input
int $index index
Output
mixed  

line 356

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 392

offsetUnset

public void offsetUnset (int $index)

Removes child node (\ArrayAccess implementation).

Implementation of:

ArrayAccess::offsetUnset
Input
int $index index
Output
void  

line 416

removeChildren

public void removeChildren ()

Removed all children.

Output
void  

line 458

render

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

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

Input
int $indent indent
Output
string  

line 236

setHtml

public Html setHtml (string $html)

Sets element's HTML content.

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

line 102

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 277

setText

public Html setText (string $text)

Sets element's textual content.

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

line 500

startTag

public string startTag ()

Returns element's start tag.

Output
string  

line 180

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

__clone

public void __clone ()

Clones all children too.

Output
void  

line 155

__get

public mixed & __get (string $name)

Overloaded getter for element's attribute.

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

line 143

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

__toString

public void __toString ()

Output
void  

line 167

__unset

public void __unset (string $name)

Overloaded unsetter for element's attribute.

Input
string $name HTML attribute name
Output
void