[ Pobierz całość w formacie PDF ]
.After the in tagyou finally close your HTML bulleted list with a closing ul HTML tag and the standard_html_footer isinserted to close the document.In Tag Special VariablesThe in tag provides you with some useful information that lets you customize your HTML while you areiterating over a sequence.For example, you can make your file library easier to read by putting it in anHTML table and making every other table row an alternating color, like this, as shown in Figure 4-5.Figure 4-5 File listing with alternating row colors.The in tag makes this easy.Change your file library method a bit to look like this:In Tag Special Variables 63IntroductionHere an if tag is used to test for a special variable called sequence-even.The in tag sets this variable to atrue or false value each time through the loop.If the current iteration number is even, then the value is true, ifthe iteration number is odd, it is false.The result of this test is that either a tr tag with a gray or no background is inserted into the document forevery other object in the sequence.As you might expect, there is a sequence-odd that always has theopposite value of sequence-even.There are many special variables that the in tag defines for you.Here are the most common and useful:sequence-itemThis special variable is the current item in the iteration.In the case of the file library example, each time through the loop the current file of the iteration isassigned to sequence-item.It is often useful to have a reference to the current object in the iteration.sequence-indexthe current number, starting from 0, of iterations completed so far.If this number is even,sequence-even is true an sequence-odd is false.sequence-numberThe current number, starting from 1, of iterations completed so far.This can be thought of as thecardinal position (first, second, third, etc.) of the current object in the loop.If this number is even,sequence-even is false and sequence-odd is true.sequence-startThis variable is true for the very first iteration.sequence-endThis variable is true for the very last iteration.These special variables are detailed more thoroughly in Appendix A.DTML is a powerful tool for creating dynamic content.It allows you to perform fairly complex calculations.In Chapter 7, "Advanced DTML", you'll find out about many more DTML tags, and more powerful ways touse the tags you already have seen.Despite its power, you should resist the temptation to use DTML forcomplex scripting.In Chapter 8."Advanced Zope Scripting" you'll find out about how to use Python and Perlfor scripting business logic.In Tag Special Variables 64Chapter 5: Creating Basic Zope ApplicationsIn Chapters 3 and 4 you learned about basic Zope objects and DTML.In this chapter you'll see how you canbuild simple but powerful web applications using these tools.In later chapters of the book you'll discovermore complex objects and more complex DTML.However, the design techniques covered in this chapter arestill relevant.Building Applications with FoldersFolders are the "basic building blocks" of Zope applications.Folders allow you to organize your Zopeobjects, and actively participate in your web applications.Folders are given behavior by adding scripts tothem.Scripts and folders work together to build simple applications.Folders provide structure for your informationand also provide a framework for your site's behavior.Later in this chapter, an example of a simple guestbook application based on this design concept is given.A folder is used to hold the methods, scripts and dataof the guest book application, the scripts provide behavior that define how the application works, and themethods provide presentation to the application.For example, suppose you have an Invoices folder to hold invoices.You could create objects inside thatfolder named addInvoice and editInvoice to allow you to add and edit invoices.Now your Invoices folderbecomes a small application.Zope's simple and expressive URLs are used to work with the invoices application.As you've seen, you candisplay a Zope object by going to its URL in your browser.So for example, the URLhttp://localhost:8080/Invoices/addInvoice calls the addInvoice object on the Invoices folder.This URL mighttake you to a screen that lets you add an invoice.Likewise, the URLhttp://localhost:8080/Invoices/editInvoice?invoice_number=42 calls the editInvoice object on theInvoices folder and passes it the argument invoice_number with a value of 42.This URL could allow you toedit invoice number 42.Calling Objects on Folders with URLsThe invoices example demonstrates a powerful Zope feature.You can call an object on a folder by going to aURL that consists of the folder's URL followed by the id of the object.This facility is used throughout Zopeand is a very general design pattern.In fact you are not just restricted to calling objects on folders.You'll seelater how you can call objects on all kinds of Zope objects using the same URL technique.For example suppose you want to call an object named viewFolder on one of your folders.Perhaps you havemany different viewFolder objects in different locations.Zope figures out which one you want by firstlooking in the folder that you are calling the object on.If it can't find the object there it goes up one level andlooks in the folder's containing folder [ Pobierz całość w formacie PDF ]