1
maxxy
template - table design
  • 2007/10/16 16:46

  • maxxy

  • Quite a regular

  • Posts: 286

  • Since: 2007/6/11


I'm currently working on some heavy modification to the template of one of my module

Code example

<{foreach item=item from=$block.items}>
data data data
<{/foreach}>


I want the data to be represent in a table and look something like below : 3 column 3 row

Resized Image


i have 9 data to show

How do I design the table so the 4th data will go automatically go to the next row ?

I’m a newbie on this thing…help me

2
zyspec
Re: template - table design
  • 2007/10/16 17:36

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


You can try something like this:
<{foreach item=item from=$block.items name=lp}>
<{if 
$smarty.foreach.lp.first}><table><{/if}>
<{if 
$smarty.foreach.lp.iteration == }><tr><{/if}>
<
td>$itemtd>
<{if 
$smarty.foreach.lp.iteration == }>tr><{/if}>
<{if 
$smarty.foreach.lp.last}>
<{if (
$smarty.foreach.lp.iteration 3) < }>
<
td colspan="<{(3 - ($smarty.foreach.lp.iteration % 3))}>">td>}><{/if}>
tr>table>
<{/if}>
<{/foreach}>


I think this code is correct but I didn't actually try it... It should get you close enough that you can debug it from there. You can also look at http://smarty.php.net to get more information

3
maxxy
Re: template - table design
  • 2007/10/17 4:32

  • maxxy

  • Quite a regular

  • Posts: 286

  • Since: 2007/6/11


thanks zyspec

but it is not working ....the page stop loading half page and didn't show my data
actually the template that i'm trying to modify is the smartsection_items_spot.html block from the smartsection module

based on your code above...what i put in my template is like below
<{foreach item=item from=$block.items name=lp}>
<{if 
$smarty.foreach.lp.first}><table><{/if}>
<{if 
$smarty.foreach.lp.iteration == }><tr><{/if}>
<
td>

<{include 
file="db:smartsection_singleitem_block.html" item=$item}>

td>
<{if 
$smarty.foreach.lp.iteration == }>tr><{/if}>
<{if 
$smarty.foreach.lp.last}>
<{if (
$smarty.foreach.lp.iteration 3) < }>
<
td colspan="<{(3 - ($smarty.foreach.lp.iteration % 3))}>">td>}><{/if}>
tr>table>
<{/if}>
<{/foreach}>



i turned on the smarty template debug and nothing show up

can you test the code or can you point me to a easy smarty template article on this



ps: sorry for my poor english...

4
zyspec
Re: template - table design
  • 2007/10/17 20:11

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


It may have been how I was trying to calculate the number of columns to span during the last iteration - now that I look at it I don't think Smarty can do what I was trying to do. Try this code to see if it works. I tried it using a test array of data and it appears to work.

<{foreach item=item from=$block.items name=lp}>
  <{if 
$smarty.foreach.lp.first}><table><{/if}>
  <{if 
$smarty.foreach.lp.iteration == }><tr><{/if}>
    <
td><{include file="db:smartsection_singleitem_block.html" item=$item}>td>
  <{if 
$smarty.foreach.lp.iteration == }>tr><{/if}>
  <{if 
$smarty.foreach.lp.last}>
    <{if (
$smarty.foreach.lp.iteration == 1)}><td colspan="2">td><{/if}>
    <{if (
$smarty.foreach.lp.iteration == 2)}><td>td><{/if}>
    tr>table>
  <{/if}>
<{/foreach}>

5
maxxy
Re: template - table design
  • 2007/10/18 2:32

  • maxxy

  • Quite a regular

  • Posts: 286

  • Since: 2007/6/11


wow...thank you very much zyspec...it works like a charm

6
demian
Re: template - table design
  • 2010/11/13 13:56

  • demian

  • Quite a regular

  • Posts: 225

  • Since: 2008/4/29


how do i do the above without using table .... ?

Login

Who's Online

132 user(s) are online (54 user(s) are browsing Support Forums)


Members: 0


Guests: 132


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Dec 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits