Home arrow PHP arrow Page 10 - Template-Based Web Development With patTemplate (part 2)

Simple Simon - 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.

TABLE OF CONTENTS:
  1. Template-Based Web Development With patTemplate (part 2)
  2. Scoping It Down
  3. Speaking In Tongues
  4. Looping The Loop
  5. Legal Eagles
  6. Hide And Seek
  7. Setting Things Right
  8. Fortune Favours The Brave
  9. Running On Empty
  10. Simple Simon
  11. Brain Dump
  12. A Well-Formed Example
  13. Crash Bang Boom
  14. Endgame
By: Team Melonfire, (c) Melonfire
Rating: starstarstarstarstar / 10
June 19, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
In case the standard template type doesn't meet your needs, and the conditional one is too complicated, patTemplate offers you the best of both worlds with its "simpleCondition" template type. This template type defines a list of variables that are required for the template to be displayed; if these variables don't exist, the template will never be displayed.

With this in mind, it's possible to simplify and rewrite the example on the previous page as an illustration of the concept:


<patTemplate:tmpl name="fortune" type="simpleCondition" requiredvars="DAY"> <html> <head> <basefont face="Arial"> </head> <body> And today's fortune is: <br> What sane person could live in this world and not be crazy? </body> </html> </patTemplate:tmpl>
And here's the script:

<?php // include the class include("include/patTemplate.php"); // initialize an object of the class $template = new patTemplate(); // set template location $template->setBasedir("templates"); // add templates to the template engine $template->readTemplatesFromFile("fortune.tmpl"); // comment the next line and the template will never be displayed $template->AddVar("fortune", "DAY", date("D", mktime())); // parse and display the template $template->displayParsedTemplate("fortune"); ?>


 
 
>>> More PHP Articles          >>> More By Team Melonfire, (c) Melonfire
 

blog comments powered by Disqus
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap

Dev Shed Tutorial Topics: