Online
 
Friday, 09 January 2009
 
 
More article:
Related Content:

php The What and Why of Templates
 

In PHP, the most common method of separating presentation and application logic is through the use of templates. A template is (in general) an HTML document that contains special markers and/or control structures. In fact, PHP was originally designed to be a simple macro language that functioned much like a template engine.

Separating Common Elements from Code

As PHP grew more popular, it was quickly adopted by Web developers across the world because it was very easy to learn. This ease of development made PHP one of the best languages for rapid application development and prototyping. Unfortunately, the same capabilities that make PHP such an excellent language for prototyping quickly also make it very easy to create unmanageable code. Developers soon realize that as websites become larger, making their websites more modular becomes very important. The most common solution to this problem is to separate the website into common elements that can be included via a PHP include statement. For instance, in most cases, you can separate any given website into three separate elements: a header, a footer, and the actual content. shows how to separate your average Web page into three segments:

Listing 7.1. Your Typical Segmented Web Page

segments.php

<?php
function display_head($title="Your typical web page") {
?>
<HTML>
<HEAD><TITLE><?=$title?></TITLE></HEAD>
<BODY>
<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>
<TR>
<TD>
<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>
<TR><TD><A href="products.php">Products</A></TD></TR>
<TR><TD><A href="contact.php">Contact</A></TD></TR>
<TR><TD><A href="about.php">About Us</A></TD></TR>
</TABLE>
</TD>
<TD>
<?php } // end of display_head() function

function display_foot() {
?>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
<?php } // end of display_foot() function
?>
Tags: Add more tags...,
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment. Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

Mobile Wallpaper 71
Statistic


Last Post

 
Top! Top!