Substitutes special template tags with given content.
This is just another template class for HTML/XML/text templates. BUT it is the result of studying several other template engines and tries to merge all advantages. This text explains you two things:
How To Use
A usage example:
Why This Way
This class was written for a simple project. It's just one class, not a whole framework with caching and so on. It supports everything, that a simple template engine should support. But not more. Keep it simple.
Why do you use single quotes for variables?
There are three reasons:
Besides, if you like another syntax, just change the constants in the script. It's free.
Why don't you recommend the assignArray-method?
It's no good idea to store everything in an array. The more complex your application becomes, the harder it is to remember all the array structures. Additionally some IDEs (e.g. NetBeans) support the correct renaming of variables, but not of array indices, of course.
Assigning one variable to the template is not more complicated than a new entry in an array.
And most important: Perhaps you have a full array of data from mysql_fetch_array(). But you should not insert this into a template. Normally you have more data in there than you want to present the user. And you have to encode the user data to prevent code injection. So depending on your application, perhaps you can do something like this:
But this depends on your application.
Wouldn't it be nice to define conditions for subtemplates or provide something like a for-loop syntax?
No. It's a good idea to seperate PHP and HTML cleanly. So you have all your application logic in your PHP code. Your template files only define, what can be displayed and how. If you really want to script within your HTML, then you can just use PHP itself:
Other interesting template classes:
Located in /Template.php (line 163)
Loads the content of a template file.
Creates a new instance with given string as source (not filename).
Subtemplates are defined once and will appear in the result zero or more times. Varying content and also sub-subtemplates are possible.
Replaces a template tag with the given value.
Assigns all values of the given array to the keys of the array.
Warning: This function is seldom useful. Don't assign arrays from your database without encoding the data. See documentation above.
Returns the parsed result.
Regular expression for subtemplates.
It uses the following pattern modifiers:
The beginning of a tag to substitute. Tag example: 'bar'
The beginning of a tag to substitute. Tag example: 'foo'
Documentation generated on Sat, 08 Oct 2011 16:48:41 +0200 by phpDocumentor 1.4.3