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

Speaking In Tongues - 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.

  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


Related, though in a tangential manner, to the material discussed on the previous page, is the "varscope" attribute. This attribute allows you to import the values of template variables from other templates into the current template, thereby reducing the number of calls you have to make to addVar(). Here's a quick example:

<patTemplate:tmpl name="main" varscope="lang"> Would you like me to speak with you in {LANG}? </patTemplate:tmpl> <patTemplate:tmpl name="lang"> {LANG} </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("lang.tmpl"); // define a value for the LANG variable in the "lang" template $template->addVar("lang", "LANG", "Japanese"); // parse and display the "main" template // since this template inherits values from "lang" // the value of LANG in this template will automatically be set $template->displayParsedTemplate("main"); ?>
In this case, I have two templates, "main" and "lang". Both contain references to the template variable {LANG}. However, although the template variable {LANG} has been assigned a value in the "lang" template, no such assignment has been made for the "main" template. Despite this, the "main" template will inherit the correct value from the "lang" template, via the "varscope" attribute specified in its opening tag.

This is clearly demonstrated in the output of the script above:

Would you like me to speak with you in Japanese?

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- 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...

Developer Shed Affiliates


Dev Shed Tutorial Topics: