Categories > TinyButStrong general >

Condition with fields in "then" and "else"

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: FunkyFish
Date: 2013-02-27
Time: 13:57

Condition with fields in "then" and "else"

Hi,

I'm new with TinyButStrong (so maybe I missed it in the manual). But is it possible to use a field in "then" or in "else" of the condition. For example:

[user.isOnline;if [val]=1;then [user.name];else [text.noLogin];]

That the output prints the field "user.name" of the user when it's logged in, and else a "text.noLogin". De field "text.noLogin" comes from the database, because it's multilanguage.

Thanks in advance!
By: Sarah
Date: 2013-02-27
Time: 20:26

Re: Condition with fields in "then" and "else"

Yes, you can use fields in the then and else sections of a conditional. The issue with your code appears to be order of operations related. As I understand, aside from [val] (which is special), tags nested inside of other tags need to merge before their parent, meaning user.isOnline has to merge after user.name, which won't happen since they are dependent on the same block. Try accessing your block using it's global accessor (though this can be a perfomance hit):

Assuming:
$TBS->MergeBlock('user', $users)
Then:
[onshow;users.[user.$].isOnline; if [val]=1;then '[user.name]';else '[text.noLogin]']

This way, when block 'user' merges, the tag will look like:
[onshow;users.<Current User Key, perhaps 1? or Sarah if its associative?>.isOnline; if [val]=1;then '<Current user name, maybe Sarah?>';else '<Whatever your no login text is>']

e.g.:
[onshow;users.11.isOnline; if [val]=1;then 'Sarah';else 'You are not logged in.']

Which TBS can then merge (since everything is now essentially a static string).


I'm using < and > here to denote data that has been filled in, these symbols would not be there.