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,
    Your data

...such that if the variable were true you would get: -

<span class="friend_class">
    Your data





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
ZPT mailing list

Reply via email to