Categories > TinyButStrong general >

I need help with conditional statements

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: John
Date: 2010-11-24
Time: 02:55

I need help with conditional statements

I find the manual and the examples sections useful more most topics concerning TBS but I wish there were more examples for conditional statements. There seem to be many different ways to use conditionals but I'm not sure of the best way to implement what I need.

I'm using a TBS template to dynamically produce an option dropdown with multiple entries.
<option value="[author_checklist.id;block=option]">
[author_checklist.name;block=option]
</option> 

I'd like to have one of my dynamically created entries be selected if the value of author_checklist.id is the same as the value of a variable named authorid. I've tried a bunch of different permutations of the syntax I see for conditonals in the examples section and the manual but none of them are working for me as I'd like. I was able to get a dynamically created checklist to check items as I'd like using conditionals but still can't get my option values to work as I need.

Here's my code as it is right now:
<option value="[author_checklist.id;block=option]" [onshow;block=begin;when[author_checklist.id]=authorid] selected="selected"
[onshow;block=end]>
[author_checklist.name;block=option]

I realize I may have made this code more complex than it needs to be but I'm really confused now and have resorted to just trying random things.
By: John
Date: 2010-11-24
Time: 04:38

Ok, I solved my problem

This code works as I need it work:
<option value="[author_checklist.id;block=option]"
[onshow;block=begin;when [author_checklist.id]=[onload.authorid]]selected="selected"[onshow;block=end]>
[author_checklist.name;block=option]
</option>

I am really enjoying getting to now TBS but I'd appreciate it if you guys would include a lot more examples of conditional statements. There are quite a few ways to write conditonals and not all of them seem to work as I would have guessed.
By: Skrol29
Date: 2010-11-24
Time: 10:12

Re: Ok, I solved my problem

Hi,

Since TBS 3.6.0 there is a smart and optimized way to perform option selection.
The new parameter "atttrue" helps to merge boolean attributes. Parameter "atttrue" goes with parameter "att" which helps to merge general attributes.

So the best solution is something like:
<option value="[author_checklist.id;block=option]"> [author_checklist.id;att=selected;atttrue=[onload.authorid]] [author_checklist.name] </option>

Another good way is to use conditional sections for the block, like this:
<option value="[author_checklist.id;block=option;when [author_checklist.id]=[onload.authorid]]" selected="selected"> [author_checklist.name] </option>
<option value="[author_checklist.id;block=option;default> [author_checklist.name] </option>

I agree we could give more conditional examples. This is a key think. We'll work on it.
By: ege
Date: 2010-11-26
Time: 23:12

Re: Ok, I solved my problem

Not as elegant as Skrol's examples but I have been coding this stuff for the past 3 years like this:
<option value="[author_checklist.id;block=option]" [author_checklist.id;if [val]=[onload.authorid];then selected="selected";else '']> [author_checklist.name] </option>

We absolutely need more examples, not only in conditional part, but in every section in general.