Documentation::Step by step - AvantTemplate: Template Class for PHP

+Step by step
+Template Syntax

AvanTemplate Logo SourceForge Logo
Step by step

  1. Prepare template file to be processed
    variable to be replace is written like this. "[%name%]". "[%" is called "prepend" and "%]" is called "append".
  2. Include this class
    You should first include this class by require_once(), or include_once().
  3. Instantiate Class
    Instantiate class using "new". First argument is the directory where template files resides. Note that it must be full path. Second argument is boolean value indicating whether it must handle multi-byte string safely. -mb-string must be enabled to set this argurment "TRUE"
    $t = new AvanTemplate('/usr/local/apache/htdocs/temp/', false);
  4. Set variable
    Set variable using its setValue() method. First argument is name of the variable, one defined by your template file as [%name%]("name" is the name of the variable to be replaced). Second argument is the value to replace with.
    $t->setValue('name', 'Joe the programmer');
  5. Process the template file
    Process the template file by its method format(). First argument is the file name of the template file to be processed. File name is relative to the path specified by first argument of class instantiation(constructor). This method returns processed contents.

Author: Naoki Shima; E-mail: naoki at avantexchange dot com; All Copyrights Reserved. ©