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

Hide And Seek - 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
You can alter the visibility of a particular template via its "visibility" attribute. Consider the following example:


<patTemplate:tmpl name="main"> I spy, with my little eye... <br> <patTemplate:link src="toaster" /> </patTemplate:tmpl> <patTemplate:tmpl name="toaster" visibility="hidden"> ...a template beginning with T </patTemplate:tmpl>
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("toaster.tmpl"); // parse and display the template $template->displayParsedTemplate("main"); ?>
And here's the output:

I spy, with my little eye...
Since the "visibility" attribute of the second template is set to "hidden", it will never be displayed by the template engine. In order to display it, you'll need to turn visibility to "visible" (or just remove the "visibility" attribute altogether):

<?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("toaster.tmpl"); // turn visibility on for "toaster" template // comment out the next line to have the template vanish $template->setAttribute("toaster", "visibility", "show"); // parse and display the template $template->displayParsedTemplate("main"); ?>
And now the output will include that missing section:

I spy, with my little eye... ...a template beginning with T
As you will see, though this might not seem like a big deal right now, it becomes extremely powerful when combined with the ability to programmatically alter the "visibility" attribute on the fly. That's discussed on the next page.

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

Dev Shed Tutorial Topics: