Categories > TinyButStrong general >

Question in if;then;else;

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Brandon
Date: 2006-08-28
Time: 16:51

Question in if;then;else;

Here is part of my template:
<listTable>
    <div>
        <span class="listItem">
            <h3>
                <a href="#[listTable.ID]">[listTable.name;block=listTable] [listTable.status;if [val]~=[C];then '';else ' &#8212;Tentative'] &#8212; [listTable.concertDate;frm='dddd mmmm dxx yyyy';if listTable.status='C']</a>
            </h3>
        </span>
    </div>
</listTable>

The display of listTable.status is working as expected (display nothing if = C, otherwise display 'Tentative'.
But listTable.concertDate is appearing even if listTable.status is not = C.

What am I doing wrong?
By: Brandon
Date: 2006-08-28
Time: 17:34

Re: Question in if;then;else; SOLVED, maybe

It seems that I need to have a complete if;then;else to make this work

Is there a better way?
By: NeverPanic
Date: 2006-08-28
Time: 17:56

Re: Question in if;then;else; SOLVED, maybe

[listTable.status;if [val]='C';then '[listTable.concertDate;frm="dddd mmmm dxx yyyy"]']
[listTable.status;if [val]='C';then '[listTable.concertDate;frm=\'dddd mmmm dxx yyyy\']']
One of these should do the trick, I'm not sure which one, though
By: NeverPanic
Date: 2006-08-28
Time: 17:59

Re: Question in if;then;else; SOLVED, maybe

<table>
<div>
  <span class="listItem">
   <h3>
    <a href="#[listTable.ID]">[listTable.name;block=table] [listTable.status;if [val]~=[C];then '';else ' &#8212;Tentative'] &#8212; <span>[onshow;block=span;when [listTable.status]='C'][listTable.concertDate;frm='dddd mmmm dxx yyyy']</span></a>
   </h3>
  </span>
</div>
</table>
Should also work, I consider this to be the better solution. As long as you're not writing xml output you should also use valid html tags to define your block, i.e. table, not listTable
By: Brandon
Date: 2006-08-28
Time: 18:22

Re: Question in if;then;else; SOLVED, maybe

on those very non standard tags, I eliminated them and just used the correct <div> as the block indicator:
<div class="announce">
    <h2>Upcoming Concerts:</h2>
    <!-- list of concerts goes here -->
    <div>
        <span class="listItem">
            <h3>
                <a href="#[listTable.ID]">
                    [listTable.name;block=div]
                    [listTable.status;if [val]~=[C];then '';else ' &#8212; Tentative']
                    [listTable.concertDate;frm='dddd, mmmm dxx yyyy';if [listTable.status]~=[C];then &#8212 [val];else '']
                </a>
            </h3>
        </span>
    </div>
    <h4>
        <a href="directions.shtml" name="Directions to Shady Grove">Directions to Shady Grove</a>
    </h4>
    <h5>
        (click on a concert for details)(New Concert listings added here first...)
    </h5>
</div>

To solve my original problem, I am not sure why an onshow block is better.

[listTable.concertDate;frm='dddd, mmmm dxx yyyy';if [listTable.status]~=[C];then &#8212 [val];else '']

seems to work.
By: Brandon
Date: 2006-08-28
Time: 18:25

Re: Question in if;then;else; SOLVED, maybe

This snip was not failing.  the first form works ok - does not seem to need the escaped quotes. 

In fact, seems to work without the quotes at all.  I am not sure I like that....
By: NeverPanic
Date: 2006-08-28
Time: 19:31

Re: Question in if;then;else; SOLVED, maybe

OK, your solution is even better... I used onshow just to use anything, onload should be the default method if you have the data available when loading the template.
Due to my scripts I don't happen to have any page-specific data when calling loading the template, that's why I by default always use onshow.

Another question: Why do you use regex expression matching (~=) where a simple match (= or ==) would also work? Regex is slower in this case.
By: Brandon
Date: 2006-08-28
Time: 19:37

Re: Regex versus std equality

You are right about the REGEXes and I removed them.  They were left over from trying anything I could to get my code to work and had nothing to do with the problem :)

The actual problem seemed to be that I needed the complete if/then/else construct.  I read that 3.0 should not require this but is seems thae 3.0.5 did.  I have just loaded 3.1.1 and I do not know if it still does, but I like complete logic as long as it does not slow things down so I will probably leave it alone.
By: Skrol29
Date: 2006-08-29
Time: 01:07

Re: Regex versus std equality

Hello,

Parameter 'if' needs a 'then' or a 'else' since TBS 3.0.
But I think The 'if' can work with ony a 'else'.
By: Brandon
Date: 2006-08-29
Time: 01:11

Re: Regex versus std equality

Hmm - that sounds like an odd logical construct.  I assume if/else would imply the variable, unchanged if the 'if' evaluated true.