Zcms:is and zcms:else

From GruppoZenit
Jump to: navigation, search

zcms:is and zcms:else tags store information about performing logical operations between values from content attributes, storage or user-defined values.


Contents

zcms:is

This tag contains information about building logical expressions and validating their results. If the result is "true", the body of this tag will be executed.

Attribute Definition
operation The logical operation to be performed.

Possible values are:

  • EMPTY – The value is empty.
  • NOT_EMPTY – The value is not empty.
  • NULL – The value is empty.
  • NOT_NULL – The value is not empty.
  • NULL_OR_EMPTY – The value is empty or null.
  • NOT_NULL_AND_NOT_EMPTY – The value is not empty or not null.
  • IS_NUMERIC – Return “true” if value is numeric.
  • IS_NOT_NUMERIC – Return “true” if value is non-numeric.
  • EQUALS – Comparison operation, returns "true" when one value is the same as another.
  • NOT_EQUALS – Returns "true" when one value is different to another.
  • IN – Returns "true" when one value found in a SET of values.
  • GREATERTHAN – Return “true” if greater than the value.
  • GREATERTHAN_EQUAL – Return “true” if greater than or equals the value.
  • LESSTHAN – Return “true” if less than the value.
  • LESSTHAN_EQUAL – Return “true” if less than or equals the value.
  • PATTERN – Returns "true" when the pattern in the value is matched with an attribute or a variable.

Operation to be performed on special instances and for the Content Model related.

  • CONTENT_POSITION_FIRST – Returns "true" when the content’s position is at first place during manipulation.
  • CONTENT_POSITION_NOT_FIRST – Returns "true", when the content’s position is not at first place during manipulation.
  • CONTENT_POSITION_LAST – Returns "true", when the content’s position is at last place during manipulation.
  • CONTENT_POSITION_NOT_LAST – Returns "true", when the content’s position is not at last place during manipulation.
  • CONTENT_POSITION_ODD – Returns "true", when the content’s position is at odd place. (1, 3, 5 ….).
  • CONTENT_POSITION_EVEN – Returns "true", when the content’s position is at even place (2, 4, 6….).
  • CONTENT_EXISTS – Returns "true", when the content model has results.
  • CONTENT_NOT_EXISTS – Returns "true", when the content model has no results.
  • LAST_RECORD – Returns “true”, when the record is last one.
  • NOT_LAST_RECORD – Returns “true”, when the record is not last record.
  • FIRST_RECORD – Returns “true”, when the record is first one.
  • NOT_FIRST_RECORD – Returns “true”, when the record is not first one.
attribute Optional. Name of a content-attribute.
<zcms:is operation="EMPTY" attribute="news_title">…</zcms:is>
var Optional. Name of the storage.
<zcms:store var="ntitle" attribute="news_title" />
<zcms:is operation="EMPTY" var="ntitle">…</zcms:is>
value The value that is used to compare with. The source of the value can be from request, memory, session or content-model etc. and is supplied as expression.
<zcms:is operation="EMPTY"  value="$session[ntitle]" />
<zcms:is operation="EMPTY"  value="$request[ntitle]" />
<zcms:is operation="EMPTY"  value="$memory[ntitle]" />
operator Optional.

The operators can be "and" or "or",concatenate two zcms:is operation.

type Optional.

The attribute can be used along with operations "EQUALS","NOT_EQUALS","GREATERTHAN","GREATERTHAN_EQUAL","LESSTHAN","LESSTHAN_EQUAL" and "IN".

The value can be

  1. "NUMERIC" - numeric value is to be checked.

zcms:else

This is an extension tag wrapped within the zcms:is and has information about the execution procedures if the expression given returns "false". This tag doesn’t have any attributes.


Example: using zcms:is and zcms:else tags

An example about how to use the zcms:is tag can be the following:

<zcms:is operation="EQUALS" attribute="menu_identifier" value="$request[$1]">		  
   <zcms:escape><li class="selected"></zcms:escape>
   <zcms:else>
      <zcms:escape><li></zcms:escape>
   </zcms:else>			
</zcms:is>

An example about how to use the zcms:is tag with operator attribute can be the following:

<zcms:store var="data1" value="24" format="Number"/>
<zcms:store var="data2" value="28" format="Number"/>
<zcms:store var="data3" value="30" format="Number"/>
<zcms:store var="data4" value="21" format="Number"/>
<zcms:store var="data5" value="test"/>
<zcms:store var="data6" value="test1"/>
<zcms:is operation="LESSTHAN" var="data1" value="26">		
  <zcms:is operation="LESSTHAN" var="data2" value="26" operator="or" >	
    <zcms:is operation="LESSTHAN" var="data3" value="26" operator="and" >
      <zcms:is operation="LESSTHAN" var="data4" value="26" operator="or" >
        <zcms:is operation="EQUALS" var="data5" value="test" operator="and">
          <zcms:is operation="NOT_EQUALS" var="data6" value="test" operator="and">
            <div>The final value is true</div>
            <zcms:else>
              <div>The final value is false</div>
            </zcms:else>
          </zcms:is>
        </zcms:is>
      </zcms:is>
    </zcms:is>
  </zcms:is>
</zcms:is>


An example about how to use the zcms:is tag with type attribute can be the following:

<zcms:content name="usr">
  Numbers: <zcms:attribute name="numbers"/><br/>
  Floats : <zcms:attribute name="floats" /><br/>
  Strings: <zcms:attribute name="strings"/><br/>
  <zcms:is operation="EQUALS" attribute="numbers" type="NUMERIC" value="1.0">
       <div>True</div>
       <zcms:else>
         <div>false</div>
       </zcms:else>
  </zcms:is>
</zcms:content>


An example about how to use the zcms:is tag with "IN" operation can be the following:

<zcms:store var="set" value="{12.0,20,30}"/>
<zcms:content name="ctest" debug="true">
  <zcms:filter attribute="publish"  operation="is" value="null" plaintext="true"/>	
  <zcms:is operation="IN" attribute="amount" type="numeric"  value="$memory[set]">
    True
    <zcms:else>
      False
    </zcms:else>
  </zcms:is>
</zcms:content>
<hr/>
<zcms:store var="amt" format="number"  value="10"/>
<zcms:is operation="IN" var="amt"  type="numeric" value="{10.0,20,30.52}">
  True
  <zcms:else>
    False
  </zcms:else>  
</zcms:is>


An example about how to use the zcms:is tag with "PATTERN" operation can be the following:

<zcms:store var="data"  value="This statment contains tea and coffe"/>
<zcms:is operation="PATTERN" var="data" value="tea">
  True
  <zcms:else>
  False
  </zcms:else>  
</zcms:is>
</zcms:content>

See also

Personal tools
Namespaces

Variants
Actions
Toolbox