Set WeberTrivia.com to be my default homepage.   Suggest a Question                                               

Suggest A Question : :  Frequently Asked Questions : :  Search : :  Relevant Manuals : : 
PHP Questions : :  Linux Questions : :  MySQL Questions : : 
home  [ Login ] 

Introduction

Introduction --  What HTML_Template_Flexy can do

Introduction

HTML_Template_Flexy started it's life as a simplification of HTML_Template_Xipe, however in Version 0.2, It became one of the first template engines to use a real Lexer, rather than regex'es, making it possible to do things like ASP.net or Cold Fusion tags. However, it still has a very simple set of goals.

  • Very Simple API, easy to learn...

  • Targeted at Object based systems - default behavior is to display object variables

  • Designed to allow the documentation of available variables using PEAR standards, eg. PHPDoc comments around object variables

  • Ability to edit the templates in WYSIWYG HTML editors, without breaking the tags

  • Fast and Easy to do looping (or blocks), both for designing and runtime

How does HTML_Template_Flexy differ from other template systems

If you look around you will see there are other template systems available in PHP, they generally fall into two categories, Replacement Systems, or PHP Code builders.

Replacement systems like HTML_Template_IT, FastTemplate, PhpLib Template tend to be slower at doing block and nested block type templates and involve alot of code to add each variable to the template.

Php Code builders like Flexy, Smarty, SimpleTemplate (now HTML_Template_Xipe) tend better at more complex templates, and can offer a better approach to extendability.

With Version 0.2, and the introduction of a full Lexer, Flexy offers unique HTML integration with it's foreach,if attributes and the ability to replace HTML Forms with standard PHP code.

Typical use example

Flexy template is normally called from within a Controller Class (in the Model,View,Controller paragam). You just send HTML_Template_Flexy, the name of the template, and the object to output. - any variable you want printing out just has to be set in the object being used to ouput.

Example 26-1. Typical usage example for HTML_Template_Flexy

<?php             /* configure the application - probably done elsewhere */ require_once 'HTML/Template/Flexy.php'; $options = &PEAR::getStaticProperty('HTML_Template_Flexy','options'); $config = parse_ini_file('example.ini',TRUE); $options = $config['HTML_Template_Flexy'];   /* the page controller class */  class controller_test  {          var $template = "home.html"; // name of template     var $title;                  // this relates to {title};     var $numbers = array();      // this relates to {numbers} , used with foreach     var $anObject;          var $element = array();      // this is where the elements are stored          /* start section - deals with posts, get variables etc.*/      function controller_test()      {         $this->start();         $this->output();     }       function start()      {         // the title         $this->title = "Hello World";                  // store an object.         $this->anObject = new StdClass;                  // assign a value to a member.         $this->anObject->member = 'Object Member';                  // create an HTML Element for the form element.         $this->elements['input'] = new HTML_Template_Flexy_Element;                  // assign a value to it         $this->elements['input']->setValue('Hello');                           for ($i = 1;$i< 5;$i++) {             $this->numbers[$i] = "Number $i";         }     }          /* output section - probably best to put this in the default_controller class */          function output() {         $output = new HTML_Template_Flexy();         $output->compile($this->template);         $output->outputObject($this,$this->elements);     }               function someMethod() {         echo "<B>Hello From A Method</B>";     }                }  /* the page controller instantaation - probably done with a factory method in your master page controller class */  new controller_test;           ?>

Now the example template,

And the output

Who's Online
Guest Users: 8
Google
Web
WeberTrivia
WeberDev
WeberForums
 Free Sample Chapters  Free Sample Chapters
  Deliver First Class Web Sites: 101 Essential Checklists
Want to learn how to make your web sites usable and accessible? Want to ensure that your sites meet current best practice, without spending hours trawling through incomprehensible specifications and recommendations from dozens of different books, research papers, and web sites? Want to make sure that the sites you build are "right the first time," requiring no costly redevelopments?

More Sample Chapters

PHP General