|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
driverfiles Smarty Rookie
Joined: 10 Aug 2003 Posts: 26 Location: Epe, The Netherlands
|
Posted: Fri Oct 17, 2003 10:20 am Post subject: HTML_Table - Dimensional array |
|
|
Hi
Currently I'm using Smarty for a directory-structure website and I'm having trouble reading out the content in a good structure.
To visualize my problem, below is how the HTML should look like (if you would view the source of the site).
<table>
<tr>
<td>{$groepen[groepen].name1}</td>
<td>{$groepen[groepen].name2}</td>
<td>{$groepen[groepen].name3}</td>
<td>{$groepen[groepen].name4}</td>
</tr>
<tr>
<td>{$groepen[groepen].description1}</td>
<td>{$groepen[groepen].description2}</td>
<td>{$groepen[groepen].description3}</td>
<td>{$groepen[groepen].description4}</td>
</tr>
---> next columns
</table>
The output will look like this:
Group 1 | Group 2 | Group 3 | Group 4
Description Group1 Descr. Gr.2 Descr. Gr.3 Descr. Gr.4
The Array looks like this:
$groepen = Array (0 => Array ('name' => 'group1'.
'description' => 'Description group1'));
Is the above possible with html_table ? I know html_table can't use multi-dimensional array's but mabey there is a mod out there ? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Oct 17, 2003 10:53 am Post subject: |
|
|
how should you table behave with sizeof($array)!=4 ?
should the number of colums incerement?
or should there be added another pair of 2 rows with 4 cols, for example ? |
|
Back to top |
|
driverfiles Smarty Rookie
Joined: 10 Aug 2003 Posts: 26 Location: Epe, The Netherlands
|
Posted: Fri Oct 17, 2003 11:19 am Post subject: |
|
|
Messju, it should just be like this:
<tr>
<td>Name 1</td>
<td>Name 2</td>
<td>Name 3</td>
<td>Name 4</td>
</tr>
<tr>
<td>Description 1</td>
<td>Description 2</td>
<td>Description 3</td>
<td>Description 4</td>
</tr>
<tr>
<td>Name 5</td>
<td>Name 6</td>
<td>Name 7</td>
<td>Name 8</td>
</tr>
<tr>
<td>Description 5</td>
<td>Description 6</td>
<td>Description 7</td>
<td>Description 8</td>
</tr>
----- etc... ------
Name 1 and Description 1 should be from the same row. Ofcourse I can do this in PHP but then it isn't template-based anymore so I would prefer it to be done by html_table or something similar if possible. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Oct 17, 2003 12:01 pm Post subject: |
|
|
okay. after reading twice over your first post, i could have guessed this.
unfortunately html_table is not very flexible. you would have to rearrange your array in php or with a modifier to be able to do what you want with html_table.
alternatively you could try to do it fully in the template.
you could adopt monte's infamous
http://smarty.php.net/contribs/examples/dynamic_table_columns/table.tpl.txt
and modify it to use more than one column.
i was in mood to try a little solution. to me it's the first time, i see use in the new simple-math-operators, that where introduced after Smarty-2.5.0 . so if you use 2.6.0-RC2 you can try this:
Code: |
<table>
{section name=tr start=0 step=4 loop=$groepen}
<tr>
{section name=td start=$smarty.section.tr.index loop=$smarty.section.tr.index+4}
<td>{$groepen[td].name}</td>
{/section}
<tr>
</tr>
{section name=td start=$smarty.section.tr.index loop=$smarty.section.tr.index+4}
<td>{$groepen[td].description|default:"&"}</td>
{/section}
</tr>
{/section}
</table>
|
if you don't consider 2.6.0-RC2 stable enough for your purposes, you have to backport the math stuff to {math}-plugin to make it compatible with 2.5.0. this shouldn't be hard either.
have fun
messju
(BTW: BHIF (be happy it's friday) ) |
|
Back to top |
|
driverfiles Smarty Rookie
Joined: 10 Aug 2003 Posts: 26 Location: Epe, The Netherlands
|
Posted: Fri Oct 17, 2003 2:02 pm Post subject: |
|
|
Thanks a LOT messju, I'm going to try this out asap and let you know if it works. Thanks again! |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|