ZPT Basics (part 1) - Practical Magic (
Page 3 of 5 )
Let's take a look at a more concrete example
of how TAL works. Start up Zope and log in to the management interface with the
user name and password that was created when you installed Zope.
As you should know by now, this is the tool that you will be using to build your
Web applications. You can use it to create documents, folders, and your own Zope
products. And the first step in this process is to create a folder to store all
the objects we're going to be creating.
Create a Folder by selecting it from the drop-down menu that appears at the top
of the page, and name it "ZPT Basics".
The next step is to navigate to the folder that you just created and add a Page
Template to it, using the process outlined above.
Give this template an ID of "MyFirstTemplate", and a title of "Hello ZPT!".
As you may have guessed by now, the object ID that you assign at each stage is
fairly important - it provides a unique identifier for the object within Zope,
which can be used to access and manipulate it from your scripts.
A default page template will be created in the "ZPT Basics" folder. Replace the
code within it with the following:
<html>
<head>
<title tal:content="template/title">The title</title>
</head>
<body>
<h2>Welcome
to <span tal:replace="here/title_or_id">content title or
id</span></h2>
This
is a Page Template with ID <em tal:content="template/id">template
id</em>
and title <em tal:content="template/title">template title</em>.
</body>
</html>
Here's the output of this template (you can see this via the "Test" option in
the Zope management interface),
and here's the corresponding HTML code generated by Zope.
<html>
<head>
<title>Hello ZPT!</title>
</head>
<body>
<h2>Welcome
to ZPT Basics</h2>
This is a Page Template with ID <em>MyFirstTemplate</em>
and title
<em>Hello ZPT!</em>.
</body>
</html>