Zope
  Home arrow Zope arrow Page 5 - ZPT Basics (part 1)
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? 
ZOPE

ZPT Basics (part 1)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 22
    2002-09-18


    Table of Contents:
  • ZPT Basics (part 1)
  • The Power Of Three
  • Practical Magic
  • Anatomy Lesson
  • Putting It All In Context

  • 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


    ZPT Basics (part 1) - Putting It All In Context
    ( Page 5 of 5 )

    You'll remember that I told you, a while back, that every TALES path expression must begin with a variable name. The TALES specification defines a number of such variables - here's a list of the most important ones:

    "nothing" - a null value

    "repeat" - a built-in TALES variable used for repetition

    "root" - the starting point for the object hierarchy

    "here" - the current context

    "template" - the template itself

    "container" - the template's container

    "request" - the request object

    You've already seen the "template" context in action - now let's take a look at the "request" context, which contains information about the current HTTP request. Consider the following example,

    You are currently viewing the URL <i tal:content="request/URL">URL comes here</i>.
    which, when rendered, displays the current URL:

    You are currently viewing the URL http://medusa:8080/ZPT%20Basics/MyFirstTemplate.
    This context also comes in handy when you're building Web forms and need to access the values of the various form variables. Consider the following simple DTML Document:

    Please enter the following details: <br> <form action="formHandler" method="POST"> <p> Your name <br> <input type="text" size="20" name="name"> <br> </p> <p> Your favourite sandwich filling <br> <input type="text" size="15" name="filling"> <br> </p> <input type="submit" name="submit" value="Hit Me"><br> </form>
    This displays the following form to the user.



    Next, create the form processing script, "formHandler", using a Page Template:

    Hello, <span tal:replace="request/form/name">name here</span>. I like <span tal:replace="request/form/filling">filling type here</span> sandwiches too. Maybe we should exchange recipes.
    Try it out - here's an example of what you might see:



    The beauty of this example lies in its simplicity. I've used the "request" context and obtained access to the form variables simply by specifying the appropriate path - the "request/form/name" path for the form variable "name", and the "request/form/filling" path for the form variable "filling".

    And that's about it for this first part of the series. In this article, I gave you a gentle introduction to the ZPT way of doing things, explaining the special "content" and "replace" TAL attributes. In the next segment, I'll be looking at a few more of TAL's special attributes, including the ones that let you define variables and write conditional statements. Make sure you tune in for that one...and until then, stay healthy!

    Note: All examples in this article have been tested on Linux/i586 with Zope 2.5.0. Examples are illustrative only, and are not meant for a production environment. Melonfire provides no warranties or support for the source code described in this article. YMMV!

     
     
    >>> More Zope Articles          >>> More By Harish Kamath, (c) Melonfire
     

       

    ZOPE ARTICLES

    - Creating Zope Products
    - Plone Content Types With Archetypes
    - Flat User Management in Zope
    - Creating Basic Zope Applications
    - Getting started with Zope for Linux and Sola...
    - ZPT Basics (part 4)
    - ZPT Basics (part 3)
    - ZPT Basics (part 2)
    - ZPT Basics (part 1)
    - Exception Handling In DTML
    - DTML Basics (part 4)
    - DTML Basics (part 3)
    - DTML Basics (part 2)
    - DTML Basics (part 1)
    - Using Zope With Apache





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