 |
Smarty
The discussions here are for Smarty, a template engine for the PHP programming language. Dedicated server web hosting provided by Guru-host.eu. |
| View previous topic :: View next topic |
| Author |
Message |
brockp Smarty n00b
Joined: 14 Feb 2012 Posts: 3
|
Posted: Tue Feb 14, 2012 11:03 pm Post subject: building div grid using nested array |
|
|
I have been digging around and I am sure someone has done this but I can't get it t work. I have a array of arrays. Each outer array element represents a 'thing' and the array that it points to has all the attributes. An array of assoc arrays.
I want to make a 3 column grid out of these. I need to nest them in divs thus each row of three items is in its own div:
| Code: |
<div class=1>
<div class=a>properties of array[0]</div>
<div class=a>peoperties of array[1]</div>
<div class=a>properties of array[2]</div>
</div>
<div class=2>
<div class=a>properties of array[3]</div>
<div class=a>peoperties of array[4]</div>
<div class=a>properties of array[5]</div>
</div> |
I tried doing this with iterators but keep mucking it up. What is the simplest way do this in smarty?
Thanks in advance |
|
| Back to top |
|
brockp Smarty n00b
Joined: 14 Feb 2012 Posts: 3
|
Posted: Thu Feb 16, 2012 3:43 am Post subject: |
|
|
To give a better idea my data passed into smarty looks like:
| Code: |
Array
(
[0] => Array
(
[id] => 1
[cat] => 1
[subcat] => 2
[width] => 24.0
)
[1] => Array
(
[id] => 2
[cat] => 1
[subcat] => 2
[width] => 24.0
)
|
I want to use each array member into the grid 3 wide. Order does not matter.
Here is what I ended up with, looks like smarty arrays are indexed from 1
| Code: |
{foreach from=$product name=outer item=p key=i}
{if ($smarty.foreach.outer.iteration-1)%3==0 or $smarty.foreach.outer.first}
<!-- new row start {$smarty.foreach.outer.iteration} -->
<div class="{cycle values="class1, class2"}">
{/if}
<div class="gallery"> <img src="/images/{$p.image}" alt="pediatric Mattress" width="125" height="82">
<p align="center">{$p.type|capitalize}</p>
<p class="size">{$p.width}" x {$p.length}" x {$p.thickness}"</p>
</div>
</div>
{if ($smarty.foreach.outer.iteration)%3==0 or $smarty.foreach.outer.last}
{* print new row stuff *}
<!-- New Row ending {$smarty.foreach.outer.iteration} -->
</div>
{/if}
{/foreach}
|
|
|
| Back to top |
|
brockp Smarty n00b
Joined: 14 Feb 2012 Posts: 3
|
Posted: Thu Feb 16, 2012 4:06 am Post subject: |
|
|
If I read the docs better I would have noted the difference between .itteration and .index
Nothing to see here move along  |
|
| 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
|