Templating Systems in PHP

A templating system in PHP provides a way of separating the code in a web page from the layout of that page. In larger projects, templates can be used to allow designers to deal exclusively with designing web pages and programmers to deal (more or less) exclusively with programming.

The basic idea of a templating system is that the web page itself contains special markers that are replaced with dynamic content. A web designer can create the HTML for a page and simply worry about the layout, using the appropriate markers for different kinds of dynamic content that are needed. The programmer, on the other hand, is responsible for creating the code that generates the dynamic content for the markers.

Example Templating Systems in PHP

 <title>User Information</title>
 <?php if (!empty($_GET['name'])) {
 // do something with the supplied values ?>
 <p><font face="helvetica,arial">Thank you for filling out the form,
 <?php echo $_GET['name'] ?>.</font></p>
 <?php }
 else { ?>
 <p><font face="helvetica,arial">Please enter the
 following information:</font></p>
 <form action="<?php echo $_SERVER['PHP_SELF'] ?>">
 <input type="text" name="name" />
 <input type="submit" />
 <?php } ?>

Leave a Comment