[Zope] ZPT: conditional omitting of a tag

Sidnei da Silva sidnei@x3ng.com
Wed, 29 Jan 2003 10:26:58 -0200


On Wed, Jan 29, 2003 at 10:05:43AM +0100, martin f krafft wrote:
| hi there,
| 
| let's say i have something like
| 
|   <a href="#" tal:attributes="href person/homepage">
|     <span tal:replace="person/name" />
|   </a>
| 
| within a tal:repeat in a ZPT.
| 
| is there a way to test for person/homepage first, and if it does not
| exist, just omit the <a> tag but publish the <span> tag (effectively
| printing the name without a link)?
| 
| right now i am doing it like so:
| 
|   <div tal:condition="person/homepage">
|     <a href="#" tal:attributes="href person/homepage">
|       <span tal:replace="person/name" />
|     </a>
|   </div>
|   <div tal:condition="not:person/homepage">
|     <span tal:replace="person/name" />
|   </div>
| 
| which is ugly at best.

I may be wrong, but I think you want something like this:

   <a href="#" tal:attributes="href person/homepage"  
      tal:omit-tag="person/homepage">
     <span tal:replace="person/name" />
   </a>


| also, is there an 'else' construct in TALES?

Nope, but you can emulate it with 

python:test(condition-expr, expr-true, expr-false)

[]'s

-- 
Sidnei da Silva (dreamcatcher) <sidnei@x3ng.com.br>
X3ng Web Technology <http://www.x3ng.com.br>
GNU/Linux user 257852
Debian GNU/Linux 3.0 (Sid) 2.4.18 ppc

"Virtual" means never knowing where your next byte is coming from.