By: Mag
Date: 2008-05-04
Time: 05:17
|
Conditionnal display inside a block
Hello TBS users.
Hope my question won't be too stupid but I don't see how to do what I want.
Here is my php code and TBS template:
The test php code :
$categ[0] = array('name'=>'Category 1','id'=>1);
$categ[0]['subs'][] = array('name'=>'Sub cateogry 1.1','id'=>4,'url'=>'#');
$categ[0]['subs'][] = array('name'=>'Sub category 1.2' ,'id'=>5,'url'=>'#');
$categ[1] = array('name'=>'Category 2','id'=>'2');
$categ[1]['subs'][] = array('name'=>'Sub category 2.1','id'=>6,'url'=>'#');
$categ[2] = array('name'=>'Category 3','id'=>'3');
$categ[2]['subs'][] = array('name'=>'Sub category 3.1','id'=>7,'url'=>'#');
$categ[2]['subs'][] = array('name'=>'Sub category 3.2','id'=>8,'url'=>'#');
$categ[2]['subs'][] = array('name'=>'Sub category 3.3','id'=>9,'url'=>'#');
$categ[3] = array('name'=>'Category 4 (no sub)','id'=>10,'url'=>'index.php');
$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('a.htm');
$TBS->MergeBlock('mb','array','categ') ;
$TBS->MergeBlock('sb','array','categ[%p1%][subs]') ;
$TBS->Show() ; |
The concerned part of the template :
<dl id="menu">
<dt onclick="javascript:show('smenu[mb.#]');"[mb.#;if [val]=1;then ' class="first"']><a href="[mb.url;magnet=a;block=dt+dd;mtype=m+m;noerr]">[mb.name]</a></dt>
<dd id="smenu[mb.#]">
<ul>
<li><a href="#[sb.id]">[sb.name;block=li;p1=[mb.$]]</a></li>
</ul>
</dd>
</dl> |
Well, it works. But I would like the dd tag and its content not to be rendered when mb.url is empty (so either there is a link inside the dt tag, or there is the dd with a list inside, but not both at a time).
I am searching for a while now but I didn't find how to have a conditionnal display for the dd tags and its content. I may miss something, I guess.
Can somebody help me ?
Thanks.
|
By: ege
Date: 2008-05-04
Time: 14:26
|
Re: Conditionnal display inside a block
Hi Mag.
I very frequently come across this in my own code as well and typically use the method similar to the following snippet. My solution is NOT wysiwyg editors friendly, but I always hand code html anyways, so it's not a problem for me:
<dl id="menu">
<dt onclick="javascript:show('smenu[mb.#]');"[mb.#;if [val]=1;then ' class="first"']><a href="[mb.url;magnet=a;block=dt+dd;mtype=m+m;noerr]">[mb.name]</a></dt>
<dd id="smenu[mb.#]">
[onshow;block=dd;when [sb.url]!='']
<ul>
<li><a href="#[sb.id]">[sb.name;block=li;p1=[mb.$]]</a></li>
</ul>
</dd>
</dl>
Hope that helps.
|
By: Mag
Date: 2008-05-04
Time: 19:44
|
Re: Conditionnal display inside a block
Tank you ege, it helped me a lot.
The final template I did is the above one:
<dl id="menu">
<dt onclick="javascript:show('smenu[mb.#]');"[mb.#;if [val]=1;then ' class="first"';else '']>
<a href="[mb.url;magnet=a;block=dt+dd;mtype=m+m;noerr]">[mb.name]</a>
</dt>
<dd id="smenu[mb.#]">[onshow;block=dd;when [mb.url]=='']
<ul>
<li><a href="[sb.url]">[sb.name;block=li;p1=[mb.$]]</a></li>
</ul>
</dd>
</dl> |
I do not understand why it works with the operator == and not with the single one =, as online manual does not make difference between the two operators but well, now it does what I want it to do :)
Thank you very much for your help.
|
By: ege
Date: 2008-05-04
Time: 22:03
|
Re: Conditionnal display inside a block
You welcome.
I don't know about the single = operator as I haven't used it. On the other hand you said "But I would like the dd tag and its content not to be rendered when mb.url is empty" but you used ==. That means "display the dd block when mb.url is equal to empty" which is the opposite of what you asked for. I'm assuming you actually wanted the dd to be rendered when mb.url is not empty.
|
By: ege
Date: 2008-05-04
Time: 22:05
|
Re: Conditionnal display inside a block
Oh, I'm confused :). What I meant is this: I'm assuming you actually wanted the dd to be rendered when mb.url is empty, since when it's not empty you display it within dt.
|
By: Mag
Date: 2008-05-05
Time: 05:20
|
Re: Conditionnal display inside a block
Yes, you are right, I made a mistake in my first message.
I am sorry but english is not a language I speak that well.
Thank you again for your help :)
|
|
Posting in progress.
Please wait...
|