Ins: control structures

Back to Ins homepage

prev next

1. ins-if

Conditional output can be done either as ins-if attribute in any tag, or as if attribute in ins tag. In the code below, we used $data = ["x"=>1];.
<div ins-if="$x==1">one</div>
<div ins-if="$x==2">two</div>

<ins if="$x==1">one</ins>
<ins if="$x==2">one</ins>

Result

one
one

2. ins-if-attr

Empty attributes are always removed. To set boolean attributes, add them in ins-if-attr attribute as a list (comma or semicolor separated) with each item in form condition:attribute, where attribute is added when condition is satisfied.
<input ins-if-attr="$x==1:disabled; $x==2:required">

Result

3. ins-class

Class attribute contains space-separated values and ins-class is an Ins attribute to generate it conditionally. This attribute uses the same syntax as ins-if-attr explained above.
<input ins-class="1==1:one; 1==2:two; 1==1:three">

Result