Home arrow PHP arrow PHP Fast Template

PHP Fast Template

Why separate presentation from logic?The simple answer to the question is, "It keeps things simple". If presentation wasn't separated from logic around your house, you'd have to be an electrician to replace light-switch covers. The same goes for large-scale web applications. Graphic designers shouldn't need to be software engineers in order to update the fonts in a web page. Separating logic from presentation makes that possible.

TABLE OF CONTENTS:
  1. PHP Fast Template
  2. Assigning templates to objects
  3. Assigning variables to FastTemplate objects
  4. MySQL Data parsed through FastTemplates
  5. Multiple templates: Rows of data into a table
  6. Summary
By: Ian Felton
Rating: starstarstarstarstar / 27
July 02, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
First, what is the difference between presentation and logic. Its the difference between dealing with the appearance of an apple and dealing with its genetic code. With web applications, presentation includes HTML tags, basic Javascript such as rollover effects, FLASH and anything else in that vein. Logic includes all of the software written in Python, Perl, PHP, or the p-p-p-particular language of choice which best solves the problem at hand.
So when writing web applications, why separate the two?

The simple answer to the question of why presentation should be kept separate from logic is, "It keeps things simple". If presentation wasn't separated from logic around your house, you'd have to be an electrician to replace light-switch covers. The same goes for large-scale web applications. Graphic designers shouldn't need to be software engineers in order to update the fonts in a web page. Separating logic from presentation makes that possible.

There are many ways to accomplish this, but in this article we are going to focus on one method using PHP and an external class called FastTemplate. This class can be downloaded from: http://www.thewebmasters.net/php/

Reminder: Sometimes separating presentation from logic is overkill. Determine the scope of your project.

{mospagebreak title=Placing FastTemplate Variables in HTML Templates} It's very simple to include data from an application's business logic into HTML templates. HTML templates are files consisting of HTML with placeholders for dynamic data.

Whenever dynamic data needs a place holder in the HTML template, place the variable name between curly braces.

Ex:

<HTML> <BODY> {HOUSE} <P> This is a house. </P> </BODY> </HTML>
The variables can be anything that the FastTemplate class can parse: alphanumeric symbols and the underscore, or {(A-Z0-9_)+} for you reg ex lovers. Always keep these variables descriptive of the data that will fill it. Remember, graphic designers will ideally be editing these templates, so they need to know exactly what is going there. Creating charts that index which templates contain specific variables is useful if the need ever arises to change the names of any of them.

{mospagebreak title=Including the Fast Template Module in PHP Code} So how does the data get from code into the HTML templates? First, the FastTemplate class file must be included in the PHP code. Accomplish this the same as including any external class file. Here is the code to include the FastTemplate class file in a PHP script:

<?php include "class.FastTemplate.php3";
Reminder: Be certain to place the path to the FastTemplate class file into the PHP.ini file's INCLUDE_PATH variable.



 
 
>>> More PHP Articles          >>> More By Ian Felton
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: