Step by step
- Prepare template file to be processed
- variable to be replace is written like this. "[%name%]". "[%" is called "prepend" and "%]" is called "append".
- Include this class
- You should first include this class by require_once(), or include_once().
- 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);|
- 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');|
- 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.