Conditions with tags

Test and Conditional attributes

These attributes test the value returned by the tag and display the enclosed content only if the tag value match the test.

  • is
  • is_not
  • in (from ionize 1.0.4)
  • expression

is / is_not

Simple test against one given value.

<!-- Displays "This is the first article" if the tag "index" has the value 1 -->
<ion:article:index is="1">
This is the first article !
</ion:article:index>
<!-- Only concerns articles from one given type -->
<ion:article:type is="bloc-small">
This is a small bloc !
</ion:article:type>
<!-- Only concerns articles which have not the type "bloc-small" -->
<ion:article:type is_not="bloc-small">
This is the first article !
</ion:article:type>

in

Test on multiple values.
Only available from ionize 1.0.4.

<!-- Check for article with no types or the given types -->
<ion:article:type in="NULL,bloc-small">
This is either an article without type or a small bloc !
</ion:article:type>

expression

Equality test
<!-- 
Each 3 picture, we add the class="last" attribute on the <li> element
This literally means "if index modulo 3 equals 0"
-->
<ion:medias type="picture" size="200" tag="ul">
   <ion:media >
       <li <ion:index expression="index%3==0"> class="last"</ion:index>>
            <img src="<ion:src />" />
       </li>
   </ion:media>
</ion:medias>


<!--
This can also be written :
-->
<ion:medias type="picture" size="200" tag="ul">
   <ion:media >
       <li <ion:index expression="index.eq(0)"> class="last"</ion:index>>
            <img src="<ion:src />" />
       </li>
   </ion:media>
</ion:medias>

When the key to use isn't given in the expression, the tag value is used :

<!-- Use of the <ion:else /> tag -->
<ion:article:title expression=".eq('My Article')">

    Yiiii, this is the article

</ion:article:title>
<ion:article:else>

    ... not happy... this is not the article

</ion:article:else>

Take care to the equal test "==" used against strings : the string must be wrapped into single quotes.

Greather than
<ion:article:index expression="index.gt(3)">
Wer're after the third article
</ion:article:index>

<!-- Shorter method : -->
<ion:article:index expression=".gt(3)">
Wer're after the third article
</ion:article:index>
Lower than
<ion:article:index expression="index.lt(3)">
Wer're before the third article
</ion:article:index>

<!-- Shorter method : -->
<ion:article:index expression=".lt(3)">
Wer're before the third article
</ion:article:index>
Multiple test

For multiple tests, the used keys must be explicitly written.

<ion:article:index expression="index.lt(3) OR index.eq(3)">
Index <= 3 !
</ion:article:index>