PHP
  Home arrow PHP arrow Page 7 - Template-Based Web Development With patTemplate (part 2)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Template-Based Web Development With patTemplate (part 2)
By: Team Melonfire, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    2002-06-19


    Table of Contents:
  • Template-Based Web Development With patTemplate (part 2)
  • Scoping It Down
  • Speaking In Tongues
  • Looping The Loop
  • Legal Eagles
  • Hide And Seek
  • Setting Things Right
  • Fortune Favours The Brave
  • Running On Empty
  • Simple Simon
  • Brain Dump
  • A Well-Formed Example
  • Crash Bang Boom
  • Endgame

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Template-Based Web Development With patTemplate (part 2) - Setting Things Right
    ( Page 7 of 14 )

    All the examples you've seen thus far have had their attributes set at design time. This is not very useful in the majority of the cases; most often, you'd prefer to alter attributes like the loop counter or the visibility at run time, on the basis of logic in your script.

    Luckily, patTemplate knows this - and it allows you to accomplish this goal via the very cool setAttribute() method, which allows you to dynamically set template attributes on the fly. Consider the following example, which demonstrates:


    <!-- index.tmpl --> <patTemplate:tmpl name="index"> <html> <head><basefont face="Arial"></head> <body> Hello, and welcome to my Web site! <!-- blah blah --> <patTemplate:link src="tip" /> </body> </html> </patTemplate:tmpl> <patTemplate:tmpl name="tip" visibility="hidden"> <p><hr> <font size="-1">New user tip: Use the Find box at the top right corner of your screen to quickly search this site.</font> </patTemplate:tmpl>
    As you can see, there are two templates in the file above; the second one is initially hidden from view. However, I can turn it on in certain cases - such as, for example, when a user visits the site for the first time. Here's the script that takes care of this for me.

    <?php // alter this to see how the script functions // when the variable is unset $newUser = true; // 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("index.tmpl"); // turn tips on if new user if ($newUser == true) { $template->setAttribute("tip", "visibility", "visible"); } // parse and display template $template->displayParsedTemplate("index"); ?>
    Depending on the value of a particular variable, I can turn the second template on or off, via a call to setAttribute().

    You can use the setAttribute() method to manipulate other template attributes as well - try it with the "loop" or "varscope" attributes to see how it works.

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

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT