TinyButStrong How to compare data value using block with php var?

1.1k views Asked by At

Environment: PHP 5.3.5 MySQL Server 5.5.8

Was Using TBS 3.7.0 Now Using TBS 3.8.2

In the sql dataset that I merged to TBS (TinyButStrong) I have a sender / recipient info. I want to display the one that is currently not user. I am having trouble getting the TBS IF THEN statements working.

IN php

$user_id = getUserId(); // returns user id
...
$TBS->MergeBlock('activity',$sql_data);

IN html, the first name is not being populated, while the last name is cause I am just directly requesting the value, even though it maybe the incorrect value.

<li>
   <div id="name">
     <a href="">
        [
         if [activity.sender_id]!=[var.user_id];
           then[activity.sender_firstname];
         else[activity.recipient_firstname];
           block=li;headergrp=message_id;ope=max:12
        ]
        [activity.sender_lastname;block=li;headergrp=message_id;ope=max:12]
      </a>
    </div> 
</li>

I have been searching and reading the TBS manual but the examples of using if / else with blocks are not like this.

Could someone please help show me what it is I am doing incorrectly?

Currently my output looks like this:

[if1!=2;then Joe;else Jane;block=li;headergrp=message_id;ope=max:12] Doe

When I just want the output to be Jane.

2

There are 2 answers

2
Skrol29 On

You can use parameter "if" alone in order to hide the value when the condition is not true.

<li>
   <div id="name">
     <a href="">
        [activity.sender_firstname;if [var.user_id]!=[activity.sender_id]]
        [activity.recipient_firstname;if [var.user_id]==[activity.sender_id]]
        [activity.sender_lastname;block=li;headergrp=message_id;ope=max:12]
      </a>
    </div> 
</li>

There is also a solution with conditional sections, but they don't work with parameter "headergrp".

5
Sarah Kemp On

You need a tag to indicate when you want to evaluate the if statement or it will never evaluate, only fill in the variables (this is why you get that output). Try:

[onshow; 
     if [activity.sender_id]!=[var.user_id];
       then[activity.sender_firstname];
     else[activity.recipient_firstname];
       block=li;headergrp=message_id;ope=max:12
    ]