Packageindex Classtrees Modulegroups Elementlist Report XML Files

XTPL Template Engine - XTPL

HtmlTag

HtmlTag

public class HtmlTag

Ultimate PHP implementation of XTHML tag. This can be used as wrapper in your PHP code
to connect the page code with the template. Or extend this class by any of yours.

Authors Vladimir Sibirov <trustware@bk.ru>
Version XTPL, v.1.2
 
Direct known subclasses: ImgTag, SelectTag, LinkTag

Public Method Summary

void

HtmlTag(string $tag, [ mixed $content ])

Constructor: creates new HtmlTag object. If $content argument is not passed, the tag won't have
void

Insert(mixed $internal_tag)

Inserts another HtmlTag into this one. $internal_tag may also contain some value.
void

Remove(int $index)

Removes tag's content element.
string

GetCode()

Renders the object into XHTML code string.
void

Parse()

Renders the object and sends the result XHTML code to output.

Public Method Details

HtmlTag

public void HtmlTag( string $tag, [ mixed $content ] )

  Constructor: creates new HtmlTag object. If $content argument is not passed, the tag won't have
closing one (<tag />). Otherwise $content may contain any string, int, etc. It is also allowedto insert HtmlTag objects into it. It is the way of tag nesting.All the tags have attributes. You can access them using accociative array HtmlTag::Attr.
Example:
<?
$br
= new HtmlTag('br');
$h1 = new HtmlTag('h1', 'Some text here');
$link = new HtmlTag('a', 'LocalHost');
$link->Attr['href'] = 'http://localhost';
$link->Attr['target'] = '_blank';
$h1_link = new HtmlTag('h1', $link);
?>

Parameter
string $tag
Tag name. e.g. 'img'
mixed $content = >>null<<
Tag content.
Returns void


Insert

public void Insert( mixed $internal_tag )

  Inserts another HtmlTag into this one. $internal_tag may also contain some value.
This is used for implementation of tag nesting.
Example:
<?
// Creating select tag using Insert method
$select = new HtmlTag('select');
$select->Attr['name'] = 'user';
for(
$i = 0; $i < count($users); $i++)
{
    
$option = new HtmlTag('option', $users[$i]);
    
$option->Attr['value'] = $i;
    
$select->Insert($option);
}
// Sending the tag to output
$select->Parse();
?>

Parameter
mixed $internal_tag
Object for insertion.
Returns void


Remove

public void Remove( int $index )

  Removes tag's content element.

Parameter
int $index
Position inside the tag.
Returns void


GetCode

public string GetCode( )

  Renders the object into XHTML code string.
Example:
<?
$h1
= new HtmlTag('h1', 'some text');
$code = $h1->GetCode();
// The result is: <h1>some text</h1>
?>

Returns string


Parse

public void Parse( )

  Renders the object and sends the result XHTML code to output.
Example:
<?
// Creating select tag using Insert method
$select = new HtmlTag('select');
$select->Attr['name'] = 'user';
for(
$i = 0; $i < count($users); $i++)
{
    
$option = new HtmlTag('option', $users[$i]);
    
$option->Attr['value'] = $i;
    
$select->Insert($option);
}
// Sending the tag to output
$select->Parse();
?>

Returns void



Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta