ZPT: conditional omitting of a tag
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. also, is there an 'else' construct in TALES? -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck NOTE: The pgp.net keyservers and their mirrors are broken! Get my key here: http://people.debian.org/~madduck/gpg/330c4a75.asc "non sposarti. trova una donna che odi e comprale una casa."
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.
also sprach Sidnei da Silva <sidnei@x3ng.com> [2003.01.29.1326 +0100]:
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>
This works, but it also causes the contents (person/name) to be omitted. I would like the <span> tag to stay and just have the <a> tag around it iff person/homepage is non-empty. -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck NOTE: The pgp.net keyservers and their mirrors are broken! Get my key here: http://people.debian.org/~madduck/gpg/330c4a75.asc "an intellectual is someone who has found something more interesting than sex." -- edgar wallace
martin f krafft wrote at 2003-1-29 13:36 +0100:
also sprach Sidnei da Silva <sidnei@x3ng.com> [2003.01.29.1326 +0100]:
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>
This works, but it also causes the contents (person/name) to be omitted. I would like the <span> tag to stay and just have the <a> tag around it iff person/homepage is non-empty. Then you should use "tal:content" rather than "tal:replace"...
Maybe, rereading the TAL documentation is a good idea... Dieter
participants (3)
-
Dieter Maurer -
martin f krafft -
Sidnei da Silva