Categories > TinyButStrong general >

Conditional block - when param

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: fpierrat
Date: 2011-10-06
Time: 21:44

Conditional block - when param

Hi,

I'd like to have a section that only appears when a condition is verified (in the example below: when $lg['a_test'] is set to 'ok')
Looked through the doc, thought it could look like this:
  <ul>
    <li>[lg.a_prenom;block=li;when [lg.a_test]='ok']:
      <ul>
        <li>[lg.a_teleph1;magnet=li]</li>
        <li>[lg.a_teleph2;magnet=li]</li>
        <li><a href='mailto:[lg.a_email1]'>[lg.a_email1;magnet=li]</a></li>
      </ul>
    </li>
    <li>[lg.b_prenom;block=li;when [lg.b_test]='ok']:
      <ul>
        <li>[lg.b_teleph1;magnet=li]</li>
        <li>[lg.b_teleph2;magnet=li]</li>
        <li><a href='mailto:[lg.b_email1]'>[lg.b_email1;magnet=li]</a></li>
      </ul>
    </li>
  </ul>

It doesn't work.
Just for tests and to better understand the "when" param, I tried to replace it with
<li>[lg.b_prenom;block=li;when 1=1] ... </li>
and with
<li>[lg.b_prenom;block=li;when 1=0] ... </li>
it made no difference, the <li> block stands always there!
By: Skrol29
Date: 2011-10-06
Time: 23:43

Re: Conditional block - when param

Hi,

I've tested your snippet "as is", and it works very well for me.
The problem you have may come with the data you are merging.
What is you version of TBS ?
Did you know that conditional sections are exclusive between each other, unless you are using parameter "several" ?

By: fpierrat
Date: 2011-10-07
Time: 08:39

Re: Conditional block - when param

Thanks,

"several": i didn't know anything of this point, I'll check, but it could be part of my problem (there's another conditional section before, but I just sent the most "regular", most easy to read ones).

Data: I had tries with simply showing [lg.a_test] and [lg.b_test], some records show "ok", other show "empty" so I don't think the problem comes from my data...

I'll tell you if the problem comes from "several" as soon as tested,
Thanks again for the rapid answer, it's very important while trying/testing a new tool!
By: fpierrat
Date: 2011-10-07
Time: 09:11

Re: Conditional block - when param

Doesn't work,
1- Here is the code, with "real" test on data for the third one, doomy test 1==1 and 1==0 on the first 2 to be sure it's not a problem with data.
Moreover, the data is shown unconditionally to see the actual values...
   <ol id="liste" start="1">        
      [lg;block=begin]
      <div class="item[lg.parite]">
         <li>
            <div class="boutons">
               ......
            </div>
            <a href="edit.php?id=[lg.id_individu]&readonly=1">
               <strong>[lg.a_nomusage] [lg.a_prenom] & [lg.b_nomnaissance] [lg.b_prenom]</strong>
            </a> <span>*** [lg.a_societe;magnet=span]</span><span>*** [lg.b_societe;magnet=span]</span>
            <ul>
               <li>Commun: [lg.c_test;block=li;several;when 1==1] xxx [lg.c_test] xxx
                  <ul>
                     <li>[lg.teleph1;magnet=li]: [lg.telephType1]</li>
                     <li>[lg.teleph2;magnet=li]: [lg.telephType2]</li>
                     <li>[lg.teleph3;magnet=li]: [lg.telephType3]</li>
                  </ul>
               </li>
               <li>[lg.a_prenom;block=li;several;when 1==0]: xxx [lg.a_test] xxx
                  <ul>
                     <li>[lg.a_teleph1;magnet=li]: [lg.a_telephType1]</li>
                     <li>[lg.a_teleph2;magnet=li]: [lg.a_telephType2]</li>
                     <li><a href='mailto:[lg.a_email1]'>[lg.a_email1;magnet=li]</a></li>
                     <li><a href='mailto:[lg.a_email2]'>[lg.a_email2;magnet=li]</a></li>
                  </ul>
               </li>
               <li>[lg.b_prenom;block=li;several;when [lg.b_test]='ok']: xxx [lg.b_test] xxx
                  <ul>
                     <li>[lg.b_teleph1;magnet=li]: [lg.b_telephType1]</li>
                     <li>[lg.b_teleph2;magnet=li]: [lg.b_telephType2]</li>
                     <li><a href='mailto:[lg.b_email1]'>[lg.b_email1;magnet=li]</a></li>
                     <li><a href='mailto:[lg.b_email2]'>[lg.b_email2;magnet=li]</a></li>
                  </ul>
               </li>
            </ul>
         </li>
      </div>
      [lg;block=end]
   </ol>

2- And here the merged result on 2 records:

Test_with_mail_and_tel Bob & Claire
    Commun: ok xxx ok xxx
        telCommun1: 234
    Bob: xxx ok xxx
        123: Tel_a_1
        456: Tel_a_2
        a@b.com
        b@c.com
    Claire: xxx ok xxx
        234: Tel_b_1
        567: Tel_b_2
Test_with_neither_tel_nor_mail &
    Commun: empty xxx empty xxx
    : xxx empty xxx
    : xxx empty xxx

3- Version: 3.7.0 for php4
Could this be a problem? ->I'm using this version because it's for a php4 OVH server, BUT I'M TESTING IT ON LOCALHOST WITH PHP5...
I suppose there's php compatibility from php5 with older code.

Thanks in advance
By: Skrol29
Date: 2011-10-07
Time: 10:23

Re: Conditional block - when param

Hi,

TBS for PHP 4 is compatible with PHP 5 if you don't set error reporting level to STRICT. A knowed bug with TBS 3.7.0 for PHP 4 will also display a notice if the error reporting level includes Notices.
So your problem does not come from this.

Nevertheless, I see that your conditional section are embedded in a main section of the same block ([lg;block=begin]...[lg;block=end]).
Embedded sections are not allowed (but with parameter "headergrp"), so the parameter "block" are simply ignored inside the main block.
Thus your conditional sections are in fact not recognized as section by TBS.
By: Anonymous
Date: 2011-10-07
Time: 11:22

Re: Conditional block - when param

Oops,

But if I use blocks one after another (and not embedded), I suppose it'll take the next record for each following block...

Maybe I can treat my "blocks" as fields, extend their scope to the surrounding <li> with "comm=li" and hide them with a "magnet" argument?
But then I need to have an empty string for the test instead of my values "ok" or "empty"...

Or maybe there's a solution with an "if ... then..." argument?
But I don't see in the manual smthg that would have as an effect : "if x==1 then merge value else hide surrounding li element".

I'll have to do some tests to get the logic of it...

Thanks
By: Skrol29
Date: 2011-10-07
Time: 11:34

Re: Conditional block - when param

> But if I use blocks one after another (and not embedded), I suppose it'll take the next record for each following block...

Only normal sections are used as alternative sections. And since you have a normal parts before and after the conditional parts, that is true that you cannot use conditional section in this case.

> Maybe I can treat my "blocks" as fields, extend their scope to the surrounding <li> with "comm=li" and hide them with a "magnet" argument?

Yes.

> But then I need to have an empty string for the test instead of my values "ok" or "empty"...

Not if you use parameter "ope=mok" and "ope=mko". It's on purpose.
  http://www.tinybutstrong.com/manual.php#html_field_prm_ope



By: fpierrat
Date: 2011-10-07
Time: 14:15

Re: Conditional block - when param

YESSSSSS,

Thanks a lot, it's very simple in fact:
<ul>
   <li>Commun: [lg.c_test;magnet=li;ope=mok:ok]
      <ul>
         <li>[lg.teleph1;magnet=li]: [lg.telephType1]</li>
         <li>[lg.teleph2;magnet=li]: [lg.telephType2]</li>
         <li>[lg.teleph3;magnet=li]: [lg.telephType3]</li>
      </ul>
   </li>
   <li>[lg.a_prenom][lg.a_test;magnet=li;ope=mok:ok]:
      <ul>
         <li>[lg.a_teleph1;magnet=li]: [lg.a_telephType1]</li>
         <li>[lg.a_teleph2;magnet=li]: [lg.a_telephType2]</li>
   ...
   ...

Works perfectly.

Thanks again.

PS. Is there a place to set a "Solved" tag anywhere in the forum subject?
By: Skrol29
Date: 2011-10-07
Time: 14:33

Re: Conditional block - when param

> PS. Is there a place to set a "Solved" tag anywhere in the forum subject?

Not yet, but good suggestion.