Log in |
Kube TutorialIntroductionThe Kube product represents a "unit of content" intended for Zope sites using Page Templates (ZPT). In other words, you use Page Templates for layout, and Kubes to store the content itself. I found Ike's overview PDF somewhat complicated for such a simple, useful product so I have written this tutorial to help future Kube users. RequirementsThis tuturial assumes you have a working knowledge of Zope and the Management Interface (ZMI) and understand the basics about Folders and ZPT. I have also assumed that you have already installed the Kube product and are ready to go. There is plenty of help on zope.org if you are unsure about any of these requirements. A Simple ExampleCreate a folder called "Kube_test". Inside it, select "Kube" from the document add list. Kubes are similar to Folders but you will see there are a some extra fields in addition to the usual ID and title. It is in these fields that you will store the content. Fill in the fields as follows:
Leave the other fields blank for now and click "Add". Congratulations, you have just created an item of content. Now we want to create a Page Template to display our content. Create a new Page Template in the kube_test Folder with ID "index_html". Copy and paste the following code into it then click save:
<html>
<head>
<title tal:content="here/title">The title</title>
</head>
<body>
<h2 tal:content="here/title">Title</h2>
<b tal:content="here/description">Introduction</b>
<p tal:content="here/full_content">Document body</p>
</body>
</html>
You have just created a Page Template to display the content contained in your Kube. Now go back to your Kube and click View. You will see the Page Template rendered with the Kube's content. The great thing about using ZPT and Kubes is that you can create as many Kubes as you like, inside sub-folders if necessary, and they will all be displayed using the same Page Template. To try this out, create another Folder inside kube_test with ID "my_documents". Inside the new folder, create another Kube called "doc" with some data in the Title, Short Description and Full Content fields. When you view this Kube, it will be automatically rendered using the index_html Page Template from the Folder above. How Does it Work?Kubes are very similar to Folders, so viewing a Kube is like viewing a Folder without an index_html inside it. Zope uses acquisition to go up the tree until it reaches a Folder containing a Page Template called index_html. Zope will then render the template within the context of the Kube so all references to This makes ZPT and Kubes a very useful combination because you can put Kubes wherever you like, and they will always be rendered using the same template. It's a very nice way of separating content from presentation. What else Does it Do?Because Kubes are similar to Folders they can contain any type of Zope object, including other Kubes. Click on one of your Kubes and then the Attachments tab. On this screen you can add other objects in exactly the same way as if it were a Folder. Then all you have to do is alter your Page Template to present the data contained in the attachments. Any use?Please let me know if this article was of use to you or if anything is unclear. tom.nixon@aim23.com |