22Customising Roundup
33===================
44
5- :Version: $Revision: 1.43 $
5+ :Version: $Revision: 1.44 $
66
77.. This document borrows from the ZopeBook section on ZPT. The original is at:
88 http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
@@ -473,7 +473,7 @@ The basic processing of a web request proceeds as follows:
4734731. figure out who we are, defaulting to the "anonymous" user
4744742. figure out what the request is for - we call this the "context"
4754753. handle any requested action (item edit, search, ...)
476- 4. render a template, resulting in HTML output
476+ 4. render the template requested by the context , resulting in HTML output
477477
478478In some situations, exceptions occur:
479479
@@ -632,11 +632,12 @@ Most customisation of the web view can be done by modifying the templates in
632632the tracker **html** directory. There are several types of files in there:
633633
634634**page**
635- This template defines the overall look of your tracker. When you
635+ This template usually defines the overall look of your tracker. When you
636636 view an issue, it appears inside this template. When you view an index, it
637- also appears inside this template. It will have a ``tal:content`` or
638- ``tal:replace`` command with the expression ``structure content`` which
639- will show the issue, list of issues or whatever.
637+ also appears inside this template. This template defines a macro which is
638+ used by almost all other templates as a wrapper for their content, using its
639+ "content" slot. It will also define the "head_title" and "body_title" slots
640+ to allow setting of the page title.
640641**home**
641642 the default page displayed when no other page is indicated by the user
642643**home.classlist**
@@ -670,8 +671,8 @@ How the templates work
670671----------------------
671672
672673Roundup's templates consist of special attributes on your template tags. These
673- attributes form the Template Attribute Language, or TAL. The commands are:
674-
674+ attributes form the Template Attribute Language, or TAL. The basic tag
675+ commands are:
675676
676677**tal:define="variable expression; variable expression; ..."**
677678 Define a new variable that is local to this tag and its contents. For
@@ -788,6 +789,51 @@ three forms:
788789 equivalent to ``item/status/checklist``, assuming that ``checklist`` is
789790 a method.
790791
792+ Tag macros, which are used in forming the basic structure of your pages,
793+ are handled with the following commands:
794+
795+ **metal:define-macro="macro name"**
796+ Define that the tag and its contents are now a macro that may be inserted
797+ into other templates using the *use-macro* command. For example::
798+
799+ <html metal:define-macro="page">
800+ ...
801+ </html>
802+
803+ defines a macro called "page" using the ``<html>`` tag and its contents.
804+ Once defined, macros are stored on the template they're defined on in the
805+ ``macros`` attribute. You can access them later on through the ``templates``
806+ variable, eg. the most common ``templates/page/macros/page`` to access the
807+ "page" macro of the "page" template.
808+
809+ **metal:use-macro="path expression"**
810+ Use a macro, which is identified by the path expression (see above). This
811+ will replace the current tag with the identified macro contents. For
812+ example::
813+
814+ <tal:block metal:use-macro="templates/page/macros/page">
815+ ...
816+ </tal:block>
817+
818+ will replace the tag and its contents with the "page" macro of the "page"
819+ template.
820+
821+ **metal:define-slot="slot name"** and **metal:fill-slot="slot name"**
822+ To define *dynamic* parts of the macro, you define "slots" which may be
823+ filled when the macro is used with a *use-macro* command. For example, the
824+ ``templates/page/macros/page`` macro defines a slot like so::
825+
826+ <title metal:define-slot="head_title">title goes here</title>
827+
828+ In your *use-macro* command, you may now use a *fill-slot* command like
829+ this::
830+
831+ <title metal:fill-slot="head_title">My Title</title>
832+
833+ where the tag that fills the slot completely replaces the one defined as
834+ the slot in the macro.
835+
836+
791837Information available to templates
792838----------------------------------
793839
@@ -812,6 +858,11 @@ The following variables are available to templates.
812858 The current tracker
813859**db**
814860 The current database, through which db.config may be reached.
861+ **templates**
862+ Access to all the tracker templates by name. Used mainly in *use-macro*
863+ commands.
864+ **utils**
865+ This variable makes available some utility functions like batching.
815866**nothing**
816867 This is a special variable - if an expression evaluates to this, then the
817868 tag (in the case of a tal:replace), its contents (in the case of
@@ -835,9 +886,6 @@ The following variables are available to templates.
835886
836887 <span>Hello, World!</span>
837888
838- **utils**
839- This variable makes available some utility functions like batching.
840-
841889The context variable
842890~~~~~~~~~~~~~~~~~~~~
843891
@@ -1078,9 +1126,34 @@ want access to the "user" class, for example, you would use::
10781126
10791127The access results in a `hyperdb class wrapper`_.
10801128
1129+ The templates variable
1130+ ~~~~~~~~~~~~~~~~~~~~~~
1131+
1132+ Note: this is implemented by the roundup.cgi.templating.Templates class.
1133+
1134+ This variable doesn't have any useful methods defined. It supports being
1135+ used in expressions to access the templates, and subsequently the template
1136+ macros. You may access the templates using the following path expression::
10811137
1082- The util variable
1083- ~~~~~~~~~~~~~~~~~
1138+ templates/name
1139+
1140+ or the python expression::
1141+
1142+ templates[name]
1143+
1144+ where "name" is the name of the template you wish to access. The template you
1145+ get access to has one useful attribute, "macros". To access a specific macro
1146+ (called "macro_name"), use the path expression::
1147+
1148+ templates/name/macros/macro_name
1149+
1150+ or the python expression::
1151+
1152+ templates[name].macros[macro_name]
1153+
1154+
1155+ The utils variable
1156+ ~~~~~~~~~~~~~~~~~~
10841157
10851158Note: this is implemented by the roundup.cgi.templating.TemplatingUtils class.
10861159
@@ -1546,13 +1619,22 @@ The link was for the item template for the category object. This translates
15461619into the system looking for a file called ``category.item`` in the ``html``
15471620tracker directory. This is the file that we are going to write now.
15481621
1549- First we add an id tag in a comment which doesn't affect the outcome
1550- of the code at all but is essential for managing the changes to this
1551- file. It is useful for debugging however, if you load a page in a
1622+ First we add an info tag in a comment which doesn't affect the outcome
1623+ of the code at all but is useful for debugging. If you load a page in a
15521624browser and look at the page source, you can see which sections come
15531625from which files by looking for these comments::
15541626
1555- <!-- dollarId: category.item,v 1.3 2002/05/22 00:32:34 me Exp dollar-->
1627+ <!-- category.item -->
1628+
1629+ Next we need to add in the METAL macro stuff so we get the normal page
1630+ trappings::
1631+
1632+ <tal:block metal:use-macro="templates/page/macros/page">
1633+ <title metal:fill-slot="head_title">Category editing</title>
1634+ <td class="page-header-top" metal:fill-slot="body_title">
1635+ <h2>Category editing</h2>
1636+ </td>
1637+ <td class="content" metal:fill-slot="content">
15561638
15571639Next we need to setup up a standard HTML form, which is the whole
15581640purpose of this file. We link to some handy javascript which sends the form
@@ -1587,7 +1669,7 @@ will be created with that name::
15871669 <td tal:content="structure python:context.name.field(size=60)">name</td>
15881670 </tr>
15891671
1590- Finally a submit button so that the user can submit the new category::
1672+ Then a submit button so that the user can submit the new category::
15911673
15921674 <tr>
15931675 <td> </td>
@@ -1596,31 +1678,43 @@ Finally a submit button so that the user can submit the new category::
15961678 </td>
15971679 </tr>
15981680
1599- So putting it all together, and closing the table and form we get ::
1681+ Finally we finish off the tags we used at the start to do the METAL stuff ::
16001682
1601- <!-- dollarId: category.item,v 1.3 2002/05/22 00:32:34 richard Exp dollar-->
1683+ </td>
1684+ </tal:block>
16021685
1603- <form method="POST" onSubmit="return submit_once()"
1604- enctype="multipart/form-data">
1686+ So putting it all together, and closing the table and form we get::
16051687
1606- <input type="hidden" name=":required" value="name">
1688+ <!-- category.item -->
1689+ <tal:block metal:use-macro="templates/page/macros/page">
1690+ <title metal:fill-slot="head_title">Category editing</title>
1691+ <td class="page-header-top" metal:fill-slot="body_title">
1692+ <h2>Category editing</h2>
1693+ </td>
1694+ <td class="content" metal:fill-slot="content">
1695+ <form method="POST" onSubmit="return submit_once()"
1696+ enctype="multipart/form-data">
16071697
1608- <table class="form">
1609- <tr><th class="header" colspan=2>Category</th></tr>
1698+ <input type="hidden" name=":required" value="name">
16101699
1611- <tr>
1612- <th nowrap>Name</th>
1613- <td tal:content="structure python:context.name.field(size=60)">name</td>
1614- </tr>
1700+ <table class="form">
1701+ <tr><th class="header" colspan=2>Category</th></tr>
16151702
1616- <tr>
1617- <td> </td>
1618- <td colspan=3 tal:content="structure context/submit">
1619- submit button will go here
1620- </td>
1621- </tr>
1622- </table>
1623- </form>
1703+ <tr>
1704+ <th nowrap>Name</th>
1705+ <td tal:content="structure python:context.name.field(size=60)">name</td>
1706+ </tr>
1707+
1708+ <tr>
1709+ <td> </td>
1710+ <td colspan=3 tal:content="structure context/submit">
1711+ submit button will go here
1712+ </td>
1713+ </tr>
1714+ </table>
1715+ </form>
1716+ </td>
1717+ </tal:block>
16241718
16251719This is quite a lot to just ask the user one simple question, but
16261720there is a lot of setup for basically one line (the form line) to do
@@ -1898,7 +1992,6 @@ Setting up a "wizard" (or "druid") for controlled adding of issues
18981992 The next page has the usual issue entry information, with the addition of
18991993 the following form fragments::
19001994
1901-
19021995 <form method="POST" onSubmit="return submit_once()"
19031996 enctype="multipart/form-data" tal:condition="context/is_edit_ok"
19041997 tal:define="cat request/form/category/value">
0 commit comments