Categories > TinyButStrong general >

Question from a newbie

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Ally
Date: 2013-01-09
Time: 04:25

Question from a newbie

Sorry about the newbie-ish question. I just recently started using TBS, but after going through the manual, I am having a hard time finding out how to do something relatively should be simple.

I want to show a certain text if only a certain value is set.

The php equivalent to what I would want would be this.

<?php
$somevar = $_POST['somevariable'];

if($somevar == 'yes'){
     echo 'This is something I am showing to only if one variable is set.'
    }
if($somevar == 'no'){
    echo 'This is a different variable.';
}

if($somevar == 'maybe'){
     echo 'This is another variable set.';
}


?>

I have gotten this to successfully work:

<table>
<tr>
<td>
This is something I am showing to only if one variable is set.[onshow_1;block=tr;when [var.$somevar]=yes]
</td>
</tr>

<tr>
<td>
This is a different variable.[onshow_1;block=tr;when [var.$somevar]=no]
</td>
</tr>

<tr>
<td>
This is another variable set.[onshow_1;block=tr;when [var.$somevar]=maybe]
</td>
</tr>
</table>


Unfortunately, this is not what I'm aiming to do.  It FUNCTIONS how I want, sort of, but I'm wondering if there is something similar to this (I know the next part is psuedo-code, sorry about that)

[onshow;somevar1=yes]This is some text.[end;somevar1=yes]  [onshow;somevar1=no]This is another text.[end;somevar1=no]   [onshow;somevar1=maybe]This is another text.[end;somevar1=maybe]



or even something similar to this would be nice too if there is a way.

<?php
    $yes = null;
    $no = null;
    $maybe = true;
?>

[onshow;yes] this is some text[end;yes] [onshow;no] more text[end;no] [onshow;maybe] and another bunch of text[end;maybe]

The idea behind this is that I could use the sets of variables to turn certain parts of texts on or off depending if a variable is set to a certain value, or even if it is set at all without relying on tr tags, or blocks of any sort.  I know the last few parts are psuedocode and are not true TBS code, but I was wondering if there is anything similar to it.  I'm sorry if this has been answered before, but I hadn't been able to find any information about it.

By: Skrol29
Date: 2013-01-09
Time: 23:44

Re: Question from a newbie

Hi,

They are several way to perform conditional display.

You can do it with conditional blocks, as you did with <tr>.
But it can works with <div>, <span>, ... even a line of text in the source of the template ("block=_")
And you can also define a block explicitly like this :
[onshow_1;block=begin;when [var.somevar]=yes]
This is something I am showing to only if one variable is set.
[onshow_1;block=end]

[onshow_1;block=begin;when [var.somevar]=no]
This is a different variable.
[onshow_1;block=end]

[onshow_1;block=begin;when [var.somevar]=maybe]
This is another variable set.
[onshow_1;block=end]

You can also perform a conditional display on a single field. Parameters if/tehn/else are done for that.
[var.somevar; if [val]=yes; then 'This is something I am showing to only if one variable is set.'; if [val]=no; then 'This is a different variable.'; else  'This is another variable set.']