[ZPT] How do I...

richard@bizarsoftware.com.au richard@bizarsoftware.com.au
Thu, 17 May 2001 17:25:34 +1000


Tony McDonald wrote:
> 1) I want to use the 'odd' path component to switch the background colour of
> a table row. I have this at the moment;
> 
> <table>
> <tr tal:attributes="bgcolor string:bogus${repeat/item/odd}"
>     tal:repeat="item python:container.module_info(module_code='bgm')"
>     bgcolor><td tal:content="repeat/item/index">index number</td><td
> tal:content="item/module_code">module Code</td><td
> tal:content="item/faculty">faculty</td><td
> tal:content="item/module_title">module title</td></tr>
> </table>
> 
> (module_info is a ZSQL method)
> 
> Which yields this
> <tr bgcolor="bogus0">
> <td>0</td><td>BGM001</td><td>ME</td><td>Biochemistry for Medicinal and
> Foundation Chemists</td></tr>
> <tr bgcolor="bogus1">
> <td>1</td><td>BGM100</td><td>ME</td><td>Biomolecules and Cell
> Biology</td></tr>
> etc
> etc
> 
> What I'd like to do is have bogus0 = blue and bogus1 = red (or whatever).
> What's the preferred way of doing this?

The best way would be to use a stylesheet. Embed something like this at the
top of the page:

<style type="text/css">
.bogus0 {
  background-color: #00ff00;
  border: none;
}

.bogus1 {
  background-color: #ff0000;
  border: none;
}
</style>

And use '<tr tal:attributes="class string:bogus${repeat/item/odd}" ...'


> 2) I'd also like to call the above PageTemplate from DTML, substituting the
> module_code='bgm' above with module_code=modcode, and pass modcode into the
> PageTemplate. I'm using this code;
> 
> tal:repeat="item python:container.module_info(module_code=request/modcode)"
> 
> Unfortunately the standard idiom
> 
> <dtml-var "mod_info(_.None,_,modcode='bgm')">
> 
> Returns an error:
> Error Type: TALESError
> Error Value: exceptions.NameError on modcode in ""

You'd be wanting to use "module_code=options/modcode" in the TAL. 


    Richard

--
Richard Jones
richard@bizarsoftware.com.au
Senior Software Developer, Bizar Software (www.bizarsoftware.com.au)