[ZPT] object attribute
Philip Kilner
phil at xfr.co.uk
Wed Nov 2 15:10:08 EST 2005
Hi Ajit,
ajit mote wrote:
> while reading 2.6Zope book i meet term attribute.....
> but not able to u'stand how to specify attribute .....
>
> if possible please give code for the below through attribute ....
> suppose i want to retrive the list of my friend's and display
> them .....
> and my best friend's name in bold .....
> so i decided to use attribute in this above case but not able
> to put that in code....
>
The "tal:attribute" tag lets you set the attributes of an HTML element.
If you look at the examples in the Zope book (The latest and greatest is
at http://www.plope.com/Books/2_7Edition), the example is of an "href"
attribute being set: -
<a href="/sample/link.html"
tal:attributes="href here/sub/absolute_url">
So, the first question might be "how should I put my friends name in
bold?". I'm not sure this is a great example, because bold is a tag, not
an attribute. However, let's say you have decided to use CSS, and so you
want to set the class attribute. A frequent case in which a class is set
as an attribute is setting a different class for odd and even rows: -
<tr tal:define="oddrow repeat/item/odd"
tal:attributes="class python:test(oddrow, 'oddclass', 'evenclass')">
In this example, a variable is defined ("oddrow") to hold the value
being tested (it could be where you define your friends name). Then the
"tal:attributes" expression sets the value of the "class" attribute to a
value based on a test of the value in the variable.
Translating this into your use-case, you would need to set a variable to
true/false by testing for your friends name, and then set the class
attribute based on that. If the true/false variable was "IsFriend", you
might do (untested): -
<span tal:attributes="class python:test(IsFriend,
'friend_class',
'stranger_class')">
Your data
</span>
...such that if the variable were true you would get: -
<span class="friend_class">
Your data
</span>
HTH
--
Regards,
PhilK
Email: phil at xfr.co.uk
PGP Public key: http://www.xfr.co.uk
Voicemail & Facsimile: 07092 070518
"You'll find that one part's sweet and one part's tart:
say where the sweetness and the sourness start."
- Tony Harrison
More information about the ZPT
mailing list