bklups
bklups

Reputation: 101

Condition depending other field

i have 2 fields (fieldA and fieldB)

what i want : - if the fieldA contains something then the fieldB should not be displayed

what i try :

<span tal:replace="here/getFieldA" />

<span tal:omit-tag="here/getFieldA"  tal:replace="here/getFieldB" />

so it doesn't work

thanks for your help

Upvotes: 2

Views: 608

Answers (3)

SteveM
SteveM

Reputation: 6048

This is a refinement of the original answer, based on the comments:

<tal:block 
    tal:define="zone here/getZoneintervention;
                thezone python:', '.join(zone);
                dep here/getDepartements;
                thedep python:', '.join(dep)">

   <span tal:condition="zone" tal:replace="thezone" /> 
   <span tal:condition="not:zone" tal:replace="thedep" /> 

</tal:block>

Upvotes: 1

Martijn Pieters
Martijn Pieters

Reputation: 1124978

What you are looking for is tal:condition, possibly combined with the not: and exists: prefixes:

<span tal:replace="here/getFieldA" />

<span tal:condition="not:exists:here/getFieldA" tal:replace="here/getFieldB" />

Alternatively, you can use the | operator, which acts like an if operator, testing existence of the first element. If it doesn't exist, it'll use the next expression, and so on:

<span tal:replace="here/getFieldA | here/getFieldB" />

The tal:omit-tag attribute means something very different. If it's expression evaluates to True, then the tag, and only the tag itself, is omitted from the output. This is best illustrated with an example:

<span tal:omit-tag="">
    <i>This part will be retained</i>
</span>

Rendering that piece of pagetemplate results in:

<i>This part will be retained</i>

The surrounding <span> tag was omitted, but the contents were preserved.

Upvotes: 4

Hanno Schulz
Hanno Schulz

Reputation: 84

Try

<span tal:condition="here/getFieldA"  tal:replace="here/getFieldB" />

The Zope Page Templates Reference http://docs.zope.org/zope2/zope2book/AppendixC.html

Upvotes: 1

Related Questions