PHP Classes
elePHPant
Icontem

File: TagBuilder-Sample.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Yves Feupi Lepatio  >  Tag Builder  >  TagBuilder-Sample.php  >  Download  
File: TagBuilder-Sample.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Tag Builder
Generate HTML tags programmatically
Author: By
Last change: --
Date: 4 years ago
Size: 1,900 bytes
 

Contents

Class file image Download
<?php

/** @see FLY_TagBuilder */
require_once 'FLY/TagBuilder.php';


$paragraphTag =
       
FLY_TagBuilder::CreateTagBuilder('p')
        ->
addCssClass('navigation computer laptop')
        ->
addCssClass('current')
        ->
removeCssClass('navigation laptop')
        ->
mergeAttribute('style', 'color: red; text-transform: uppercase;')
        ->
mergeAttributes(array(
           
'id' => 'n01',
           
'title' => 'Notebook X'
       
))
        ->
removeAttribute('style')
        ->
setInnerHtml('Look at the source code ;)');

echo
$paragraphTag->toString() . "\n";

/* Will output:
<p id="n01" class="computer current" title="Notebook X">Look at the source code ;)</p>
*/

// ----------------------------------------------------------------------------

$paragraphTag
       
->removeAllAttributes()
        ->
addCssClass('subnav subnav subNav')
        ->
setInnerHtml('Pay attention when you add CSS classes, or rather at the logic of your code...');

echo
$paragraphTag->toString() . "\n";

/* Will output:
<p class="subnav subnav subNav">Pay attention when you add CSS classes, or rather at the logic of your code...</p>
*/

echo $paragraphTag
       
->removeCssClass('subnav')
        ->
setInnerHtml("It is more simple to remove CSS class ;)")
        ->
toString() . "\n";

/* Will output:
<p>It is more simple to remove CSS class ;)</p>
*/

$imgTag = new FLY_TagBuilder('img');
$imgTag->mergeAttributes(array(
   
'src' => '',
   
'alt' => 'No image',
   
'title' => 'An image tag',
   
'onclick' => "alert('Yeah')"
));

echo
$imgTag->toString() . "\n";

/* Will output:
<img src="" alt="No image" title="An image tag" onclick="alert('Yeah')" />
*/

// Force inline tag
echo FLY_TagBuilder::CreateTagBuilder('div')->toString(FLY_TagBuilder_RenderMode::SELF_CLOSING);

/* Will output:
<div />
*/