HomePHP Page 5 - Template-Based Web Development With patTemplate (part 2)
Legal Eagles - PHP
Got the basics down? Well, here's the advanced course - thisarticle demonstrates some of patTemplate's more sophisticated features,including the ability to dynamically show or hide templates, inheritvariables, use loops and conditional branches, and create dynamic,template-based forms and error handlers.
You can source an external file into your template via the "src" and "parse" template attributes. Let's suppose I have a copyright notice, stored in the file "copyright.txt", which looks like this:
Everything here is copyright Melonfire, 2002. Be good. We have lawyers.
I can source this file by attaching the "src" attribute to a
template,
Once that's done, I can call this template from within
another template, like this:
<patTemplate:tmpl name="main">
<html>
<head>
<basefont face="Arial">
</head>
<body>
This is my Web site. It has lots of interesting stuff on it that you
might want to use for your own nefarious purposes. But before you do,
read the notice at the bottom of this page. <p> <p> <hr>
<patTemplate:link src="copyright" />
</body>
</html>
</patTemplate:tmpl>
And now, when I parse and display the "main" template, the
external file "copyright.txt" will be read and incorporated in the final output by the template engine. Here's what it looks like: