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

Running On Empty - 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
patTemplate also allows you to cover for the unexpected by specifying two additional sub-templates, one which is displayed when the decision variable cannot be matched, and one to be displayed when the decision variable is empty. Here's an example of how this might work:


<patTemplate:tmpl name="fortune" type="condition" conditionvar="DAY"> <html> <head> <basefont face="Arial"> </head> <body> And today's fortune is: <br> <patTemplate:sub condition="Mon"> Never make anything simple and efficient when a way can be found to make it complex and wonderful. </patTemplate:sub> <patTemplate:sub condition="Tue"> Life is a game of bridge -- and you've just been finessed. </patTemplate:sub> <patTemplate:sub condition="Wed"> What sane person could live in this world and not be crazy? </patTemplate:sub> <patTemplate:sub condition="Thu"> Don't get mad, get interest. </patTemplate:sub> <patTemplate:sub condition="Fri"> Just go with the flow control, roll with the crunches, and, when you get a prompt, type like hell. </patTemplate:sub> <patTemplate:sub condition="default"> Sorry, closed on the weekend. </patTemplate:sub> <patTemplate:sub condition="empty"> Sorry, cannot determine day of week. Did the world just end? </patTemplate:sub> </body> </html> </patTemplate:tmpl>
In this case, the sub-template specified as "default" will appear on Saturdays and Sundays, while the sub-template specified as "empty" will appear if {DAY} is empty. Try it out and see for yourself.

You can force patTemplate to look in the global namespace for the value of the decision variable in case it's not available locally, by adding the optional "useglobals" attribute to your template definition.

 
 
>>> 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 2 - Follow our Sitemap

Dev Shed Tutorial Topics: