Categories > TinyButStrong general >

Any experiences with blocks and conditional sections?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Olifants
Date: 2007-05-18
Time: 21:04

Any experiences with blocks and conditional sections?

Since my testing with templates I found a site with a nice little menue on it which I want to modify to fit tbs as a workout.
You can see the menue at http://www.htmldog.com/articles/suckerfish/example/
But for my regretfulness I'm not able to do this.

Here is a piece of the modified code with which I tried my luck. In the menue there are for example 2 words, than a picture and after that 3 words again. For the menue I created an array:


extract of php-file

$imgFile = $customerDirImg . '/' . 'remora3.gif';
$contactLoop = array(
                     0 => array('pointKey' => 'http://www.aldo-graphics.sh', 'pointVal' => 'ALDO Graphics'),
                     1 => array('pointKey' => 'http://www.schleswiger-ballettschule.de', 'pointVal' => 'Schleswiger Ballettschule'),
                     2 => array('pointKey' => 'image', 'pointVal' => $imgFile),
                     3 => array('pointKey' => 'http://www.csszengarden.com/tr/deutsch/?cssfile=/202/202.css&page=0', 'pointVal' => 'Zengarden Cinema'),
                     4 => array('pointKey' => 'http://www.zoo-berlin.de/erleben/jungtiere/eisbaer-knut.html', 'pointVal' => 'Knut'),
                     5 => array('pointKey' => 'http://www.amazon.de/gp/reader/3826616154/ref=sib_dp_pt/028-8205377-0982146#reader-link', 'pointVal' => 'Dynamische Webseiten in der Praxis')
                    );


extract of html-file

<li id="last">
   <div><a href="">Contact</a></div>
      <ul>
         <li><a href="[contactLoop.pointKey;block=li;when [contactLoop.pointKey]!='';several]">[contactLoop.pointVal;when [contactLoop.pointKey]!='']</a></li>
         <li><img src="[contactLoop.pointVal;when [contactLoop.pointKey]='image']" width="100" height="27" alt="Remora" /></li>
      </ul>
</li>

I would be glad, if there is somebody who is very familiar with  - or don't I need that for my code?
By: TomH
Date: 2007-05-18
Time: 21:13

Re: Any experiences with blocks and conditional sections?

Please tell what happens when you run the code...
and how it is different from what you expect.

By: Olifants
Date: 2007-05-18
Time: 21:25

Re: Any experiences with blocks and conditional sections?

First thanks for your quick reply!

And here is what I see in the html output. As you can see in the menue there is the array entry 0, 1 correct, after that he takes the entry 2 as a href too, then he takes the entry 4 and at last the img src is empty.


<li id="last">
   <div><a href="">Kontakt</a></div>
      <ul>
         <li><a href="http://www.aldo-graphics.sh">ALDO Graphics</a></li>
         <li><a href="http://www.schleswiger-ballettschule.de">Schleswiger Ballettschule</a></li>
         <li><a href="image">customer/images/remora3.gif</a></li>
         <li><a href="http://www.zoo-berlin.de/erleben/jungtiere/eisbaer-knut.html">Knut</a></li>
          <li><img src="" width="100" height="27" alt="Remora" /></li>
      </ul>
</li>


I guess my block coding is totally wrong and unusable.
By: TomH
Date: 2007-05-18
Time: 22:02

Re: Any experiences with blocks and conditional sections?

I'm not sure if I understand exactly why you are doing it that way...

If I were trying to do  something like that I'd use an 'ondata' function something like...
$TBSshow();
// the ondata=make_menu function
function make_menu($BlockName,&$CurrRec,$RecNum){
  if ($CurrRec['pointKey']!='image'){$CurrRec['menuitem'] = " <a href='$CurrRec['pointKey']'> $CurrRec['pointVal'] </a> ";
  }else{
  $CurrRec['menuitem'] = "<img align=center src='$CurrRec['pointVal'] />";
  }
}
The html might look like
<li>[contactLoop.menuitem;block=li;ondata=make_menu;htmlconv=no]</li>

The above is psuedo code - UNtested - and is only intended to give you my approach

See also the TBS examples http://www.tinybutstrong.com/examples.php
select the "Event Functions" example

Hope that helps,
TomH
By: TomH
Date: 2007-05-19
Time: 01:04

Re: Any experiences with blocks and conditional sections?

Ooops the function should be more like this...
function m_event_b1($BlockName,&$CurrRec,$RecNum){
//if ($CurrRec['pointKey'] == "image" ) $CurrRec['menuitem'] = "$CurrRec['pointVal'] ";
if ($CurrRec['pointKey'] != "image" ) $CurrRec['menuitem'] = "<a href='".$CurrRec['pointKey']."'>".$CurrRec['pointVal']."</a>";
if ($CurrRec['pointKey'] == "image" )  $CurrRec['menuitem'] = "<img src='".$CurrRec['pointKey']."' />";

That IS tested and works!

TomH
By: Olifants
Date: 2007-05-19
Time: 01:40

Re: Any experiences with blocks and conditional sections?

Thanks a lot that was a nice shot. (Only the last pointKey must be a pointVal for printing the image.)
My aim in the first coding was to clear the html from every php respectively to put every html code in the html file.
The function is fine and I think it's a good solution.
Do you think it's ok with regard to the seperated jobs of the designer and the programmer, the separation of the design and the programming?
By: TomH
Date: 2007-05-19
Time: 02:29

Re: Any experiences with blocks and conditional sections?

Maybe your first approach might work - but I couldn't find the answer - maybe others on this forum will see all this and be able to help better.

For separation of code and layout -- it is never perfect -- there is always a compromise.

But TBS will take you so much closer to a good separation than anything I have seen yet.

Best of luck,
TomH
By: Olifants
Date: 2007-05-19
Time: 09:29

Re: Any experiences with blocks and conditional sections?

Thanks really a lot.
I'm a rookie in TBS and I'm happy that there are people like you which are already so much closer to things like that and are willing to help with fun and advice.
I've spent a little time with vLIB - good template-, then I looked for TBS and considered it might be the better choice. So I'll go for it.

Nice day and good ideas

Ronny