By: antonio
Date: 2006-11-18
Time: 19:48
|
Conditional best practice question
Hi
I am a new user to TBS but love it so far. I am not sure however how to best implement the following conditionals (for a small navigation menu) on the template side... and have been quite confused about it:
if(empty($selection)){
echo "<b>all</b> | \n";
}else{
echo "<a href=\"?subcat=$subcat&sort=$sort\">all</a> | \n";
}
if($selection=='offered'){
echo "<b>offered</b> | \n";
}else{
echo "<a href=\"?subcat=$subcat&sort=$sort&selection=offered\">offered</a> | \n";
}
if($selection=='wanted'){
echo "<b>wanted</b>\n";
}else{
echo "<a href=\"?subcat=$subcat&sort=$sort&selection=wanted\">wanted</a>\n";
}
|
Advice would be most appreciated.
Thanks
|
By: TomH
Date: 2006-11-18
Time: 23:22
|
Re: Conditional best practice question
The php logig belongs in the php file -- no echo there
like this maybe, try it...
if(empty($selection)){
$select_var= "<b>all</b> | \n";
}else{
$select_var= "<a href=\"?subcat=$subcat&sort=$sort\">all</a> | \n";
}
if($selection=='offered'){
$select_var= "<b>offered</b> | \n";
}else{
$select_var= "<a href=\"?subcat=$subcat&sort=$sort&selection=offered\">offered</a> | \n";
}
if($selection=='wanted'){
$select_var= "<b>wanted</b>\n";
}else{
$select_var= "<a href=\"?subcat=$subcat&sort=$sort&selection=wanted\">wanted</a>\n";
} |
Then in your template
[var.select_var;htmlconv=no]
|
|
By: antonio
Date: 2006-11-19
Time: 20:06
|
Re: Conditional best practice question
Thanks TomH... that would indeed work. I was thinking the best practice would be to have the conditionals and all html on the template side. Guess not then.
Thanks again.
|
By: TomH
Date: 2006-11-19
Time: 22:43
|
Re: Conditional best practice question
Well, you can do that easily -- just read the doco's and see the examples on conditional blocks.
But you do not place PHP code in the template file, you use the TBS conditional block syntax.
|
By: Skrol29
Date: 2006-11-19
Time: 23:33
|
Re: Conditional best practice question
In pure HTML, it could be something like this:
<b>all[onshow_1;block=b;if [var.selection]='']</b>
<a href=\"?subcat=[var.subcat]&sort=[var.sort]\">all[onshow_1;block=a;default]</a>
|
<b>offered[onshow_2;block=b;if [var.selection]='offered']</b>
<a href=\"?subcat=[var.subcat]&sort=[var.sort]&selection=offered\">offered[onshow_2;block=a;default]</a>
|
<b>wanted[onshow_3;block=b;if [var.selection]='wanted']</b>
<a href=\"?subcat=[var.subcat]&sort=[var.sort]&selection=wanted\">wanted[onshow_3;block=a;default]</a>
|
|
By: antonio
Date: 2006-11-20
Time: 00:53
|
Re: Conditional best practice question
NICE!! Thanks Skrol29! That's exactly what I meant! :)
Minor corrections...
- 'if' doesn't work in there and should be replaced by 'when' since it is a block.
- all '\' should be removed
... but I got the general idea behind the syntax.
Guess I will have to look in the manual a bit more on how to use and what can be accomplished with onshow and onload. Great stuff!
PS: Is this method versus the single var one much slower?
|
By: Skrol29
Date: 2006-11-20
Time: 02:49
|
Re: Conditional best practice question
> PS: Is this method versus the single var one much slower?
Using [onshow_3;when ...] and [onshow_3;default;...] is a bit faster for execution but also shorter to code.
|
|
Posting in progress.
Please wait...
|