Categories > TinyButStrong general >

Re: n number of columns

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Gary
Date: 2004-12-23
Time: 20:33

Re: n number of columns

I have read this thread in the hopes of finding a simple way to accomplish something that I think should be fundamental (or at least simple) to any template processor.

Here is the problem:

Create a dynamic  html table. The best example (in the real world) that I can think of at the moment is a picture gallery where the number of columns is user defined and the number of rows is based on the total number of pictures in the gallery divided by however many columns the user has choosen.

If anything this entire thread had confused me even more. I think the confusion comes from the fact that the code snippets are just that sinippets (seeing all the code would help greatly).

I saw in this thread a post that an example may be posted?

Since if you read some of the other similar threads they are asking the same question a bit differently.

A nice simple example would be great.

As far as TBS goes I have used many a template processor in my day (PHP, Java, even some languages that go back into the early 70's) TBS is extremely easy to use and understand. It  doesnt have some of the bells and whistles of some of the other TP's but I for one rarely use "bells & whistles". Most importanly it is fast!

Any help with what I am trying to accomplish would be appreciated (and pretend I am a moron a nice simple example would be great).

Thanks
By: Skrol29
Date: 2004-12-23
Time: 20:39

Re: n number of columns

Hello Garyy,

A agree with your point of view. A typical example such as a picture gallery isa good idea. I will work on it and replace the "programmed loops" in the example set with a "dynamic column" example.

By the way,  there is a specific entry for multicolumn in the Tips & Trics forum.
By: Gary
Date: 2004-12-23
Time: 22:45

Re: n number of columns

Thanks again for the quick reply.

Below is what I am trying to accomplish using PHP code with TBS. I hat to mix HTML into PHP when I am using a template processor. From what I can see and have experimented with I think it will be easier to do it with pure PHP and HTML

<?php

// Varying either of the two below will vary the table output

$number_of_columns = 4;
$number_of_rows    = 2;

$output_data = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16');

echo '<html><header></header><body>';

echo '<table>';

$data_counter = 0;

for($rows = 0; $rows < $number_of_rows; $rows++) {
    echo '<tr>';
    for($cols = 0; $cols < $number_of_columns; $cols++) {
        echo '<td> --' . $output_data[$data_counter++] . '-- </td>';
    }
    echo '</tr>';
}

echo '</table>';

echo '</body></html>';
?>
By: Skrol29
Date: 2004-12-24
Time: 00:39

n number of columns (part 2)

This thread is the second part of thread "n number of columns". I split it because the first one was too long.
By: Skrol29
Date: 2004-12-24
Time: 01:15

Re: n number of columns

Hi Gary,

Here is an example of Template + Script that does the same as you posted.
Your problem is not only about multi-column. It is also about merging linear data (items of an array, or pictures) by performing a "return"  at the end of each last column. The solution with TBS is to expand columns at first, and then performing a serial block merging. The Html part is not long but may be not simple at first look.

HTML Template:
<html>
<head></head>
<body>

<table border="1">
<tr>[od;block=tr;serial]<td>[od_[col.val;block=td].val;block=td]</td></tr>
</table>

</body>
</html>

PHP Script:
<?php

$number_of_columns = 4;
$number_of_rows    = 2;
$number_of_items = $number_of_columns * $number_of_rows;
$output_data = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16');

include_once('tbs_class.php');
$TBS = new clsTinyButStrong;

$TBS->LoadTemplate('test.htm');
$TBS->MergeBlock('col','num',$number_of_columns); // expand columns
$TBS->MergeBlock('od',array_slice($output_data,0,$number_of_items));
$TBS->Show();

?>