Categories > TinyButStrong general >

conditional display

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Jared
Date: 2005-07-28
Time: 00:19

conditional display

I need some help getting a conditional block to show.

I am passing an array of file names. If the array is of 0 length, I need to show:
<img src="../images/[var.conf.nophoto]">
If the array is of exactly 1 length, I need to show:
<img src="../images/[file.file]"></td></tr>
If the array is greater than 1, I need to show:
<div id="stage"><img src="../images/[file.file]" border="0"></div>
</td></tr>
<tr bgcolor="#000000"><td align="center" width="300">
<table border="1"><tr>

[file;block=begin]
<td><a href="javascript:void(0)" onClick="swap('[file.file]');"><img src="../images/[file.file]" border="0" width="[file.width]" height="[file.height]"></a></td>
[file;block=end]

</tr></table></td></tr>


I can't see how to do this. I'm open to suggestions.
By: Skrol29
Date: 2005-07-28
Time: 01:09

Re: conditional display

Do you know the number of files before to read them?
By: Jared
Date: 2005-07-28
Time: 01:22

Re: conditional display

Yes, I can get the number of files.

I also have this section working:

[file;block=begin;when [file.#] == '']
<img src="../images/[var.conf.nophoto]"></td></tr>
[file;block=end]
[file;block=begin;when [file.#] == 1]
<div id="stage"><img src="../images/[file.file]"></div>[listing.files]</td></tr>
[file;block=end]
By: Skrol29
Date: 2005-07-28
Time: 01:36

Re: conditional display

I suggest that you first use a special block that will select the type of display to use (0, 1 or several files). For that, you can use the keyword 'cond' with MergeBlock() methode. TBS will then merge the block as if it was a conditional block with no data (like [onload] blocks).

If your have several files, then you merges them using another block. Otherwise you use simple Var Fields to display file information.

$nbr = count($file_list);
$TBS->MergeBlock('b1','cond'); // merges 'b1' as if it was an 'onload' block.
if ($nbr>1) $TBS->MergeBlock('b2','file',$file_list);
By: Jared
Date: 2005-07-28
Time: 02:28

Re: conditional display

Ok, so this part is stumping me. I need to do something like this:
[gnitsil;block=begin;when [gnitsil.files] > 1]
<tr bgcolor="#000000"><td align="center" width="300">
<table border="1"><tr>
[elif;block=begin]
<td><a href="javascript:void(0)" onClick="swap('[elif.file]');"><img src="../images/[elif.file]" border="0" width="[elif.width]" height="[elif.height]"></a></td>
[elif;block=end]
</tr></table>
</td></tr>
[gnitsil;block=end]

But I guess I can't nest that elif block inside of the gnitsil block because of the 'when' clause. Any suggestions on how to display this if my [gnitsil.files] variable is greater than 1?
By: Skrol29
Date: 2005-07-28
Time: 09:46

Re: conditional display

Your snippet seems correct to me.
block 'elif' is nested into block 'gnitsil' but that's not a proble for TBS because you merge them separatly.

By the way, did you tried the simplified syntax ?
[gnitsil;block=tr;...]
[elif.file;block=td;...]
By: Jared
Date: 2005-07-30
Time: 01:20

Re: conditional display

Thanks for your help Skrol29.

The light bulb has finally lit for me in regards to removing all the display logic from the template. I need to remember to keep data and display logic out of the templates.