Categories > TinyButStrong general >

Conditional display when variable exists or not

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Sebastian
Date: 2008-07-25
Time: 08:09

Conditional display when variable exists or not

Hello,

I'm a bit confused with a template. I want to show a part of a template when a variable is given and an other part if the template if the variable does not exist. How can I do that?

If
$form['COUNTRY_IDENT']
is not set than I need to show the country selector.
      <li class="InputText">[var.form.COUNTRY_IDENT;magnet=li;when [val]='';noerr]
        <label for="COUNTRY" class=""><span><font>country:</font></span></label>
        <select name="COUNTRY" id="COUNTRY">
          <option value="[countries.PRIM_ID;block=option]">[countries.IDENT_ISO] ([countries.IDENT])</option>
        </select>
      </li>

If
$form['COUNTRY_IDENT']
is set than I want to show the value and image etc.
      <li class="Text">
        <label class=""><span><font>country:</font></span></label>
        [var.form.COUNTRY_IDENT;when [val]!='';noerr]<IMG src="images/Flags/smal/F_[var.form.COUNTRY_IDENT].gif" align="absmiddle" width="30" height="20" hspace="6">
          <INPUT type="hidden" name="COUNTRY" value="[var.form.COUNTRY_IDENT]">
      </li>

Why does this not work?

regards
Sebastian

p.s.: I postet in "Your tips & tricks" but I think "Programming with TBS" is the right place for it. Sorry for double post!
By: Sebastian
Date: 2008-07-25
Time: 08:44

Re: Conditional display when variable exists or not

After reading carefully the manual I found this sentence "Thus, parameter when is taken into account only if parameter block exists in the same TBS tag."

My solution:

Variable not set: ("when" in conjunction with "block" and "onshow")
      <li class="InputText">[onshow;block=li;when [var.form.COUNTRY_IDENT]='']
        <label for="COUNTRY" class=""><span><font>country:</font></span></label>
        <select name="COUNTRY" id="COUNTRY">
          <option value="[countries.PRIM_ID;block=option]">[countries.IDENT_ISO] ([countries.IDENT])</option>
        </select>
      </li>

Variable has value: (use of "magnet")
      <li class="Text">
        <label class=""><span><font>country:</font></span></label>
        [var.form.COUNTRY_IDENT;magnet=li]<IMG src="images/Flags/smal/F_[var.form.COUNTRY_IDENT].gif" align="absmiddle" width="30" height="20" hspace="6">
          <INPUT type="hidden" name="COUNTRY" value="[var.form.COUNTRY_IDENT]">
      </li>

regards
Sebastian