Zope
  Home arrow Zope arrow Page 4 - ZPT Basics (part 4)
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 4)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    2002-10-31


    Table of Contents:
  • ZPT Basics (part 4)
  • The Idiot Box
  • The Real McCoy
  • Slotting Into Place
  • Link Zone

  • 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 4) - Slotting Into Place
    ( Page 4 of 5 )

    METAL also introduces the concept of "slots" within a macro, which may in turn be populated by other macros. Slots are placeholders within a macro definition, which can be populated dynamically every time you use the macro.

    Let's take a simple example to demonstrate how this works. Here's the macro definition, which contains a placeholder, or slot, named "link":

    <p metal:define-macro="spotlight"> Today's special is <span metal:define-slot="title"></span> </p>
    And here's the template which uses it - note how the placeholder has been filled with an actual value using the "fill-slot" attribute:

    <p metal:use-macro="container/macroDef/macros/spotlight"> Today's special is <span metal:fill-slot="title"><a href="http://www.melonfire.com/community/columns/trog/">the DTML Basics series</a></span> </p>
    Here's what the output looks like:



    By using a slot within a macro, I have the option of reusing the macro multiple times, and replacing the slot with different data each time I use it. This adds a tremendous amount of reusability to the macro, and can thereby substantially simplify the task of developing almost-but-not-quite-identical programming routines.

    Here's another, more realistic example - a macro which sets up the basic skeleton for a Web page, and uses slots to populate each instance of that page with different content:

    <span metal:define-macro="body"> <table width="100%" cellspacing="10" cellpadding="10"> <tr> <td colspan="2">Logo</td> </tr> <tr> <td><span metal:define-slot="menu">Menu</span></td> <td><span metal:define-slot="content">Content</span></td> </tr> <tr> <td colspan="2"><hr>All rights reserved.</td> </tr> </table> </span>
    Here's a sample Web page that uses the macro, and defines a particular look for the main body:

    <html> <body> <span metal:use-macro="container/macroDefs/macros/body"> <span metal:fill-slot="menu"> Select from the list below: <br> Item A <br> Item B <br> Item C <br> </span> <span metal:fill-slot="content"> <center> Content goes here <p>Content goes here <p>Content goes here <p>Content goes here <p> </center> </span> </span> </body> </html>
    Here's the output:



    And here's another one that uses the same macro, but a different look for the body:

    <html> <body> <span metal:use-macro="container/macroDefs/macros/body"> <span metal:fill-slot="menu"> &nbsp; </span> <span metal:fill-slot="content"> <table width=100% cellspacing="5" cellpadding="5"> <tr><td>Item A</td><td>Item B</td><td>Item C</td></tr> <tr><td colspan="3"><hr></td></tr> <tr><td colspan="3" align="center">Content goes here<p>Content goes here</p><p>Content goes here</p><p>Content goes here</p><p>Content goes here</p><p></p></td></tr> <table> </table></table></span> </span> </body> </html>
    Here's the output:



    As you can see, the same macro's been used in both examples; however, merely by changing the contents of the slots within the macro, I can generate a completely different look for each Web page.

     
     
    >>> 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 2 Hosted by Hostway
    Stay green...Green IT