|
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 |
luftikus143 Smarty Rookie
Joined: 14 Apr 2008 Posts: 8
|
Posted: Fri Dec 19, 2008 1:11 pm Post subject: Pass 3-dim Array to Template |
|
|
Hi there,
I have elements retrieved from a database like this:
Short Name 1,Name 1, Link 1, Short Name 2,Name 2, Link 2, Short Name 3,Name 3, Link 3
And that should be split up into something like
<a href="Link1" title="Name 1">Short Name 1</a>
<a href="Link2" title="Name 2">Short Name 2</a>
....
I can do this in the PHP part of the file, but I would prefer - I think this would be more "correct" - in the Template file.
But with a foreach(...), I only know of using this for a 2-dim array, not 3 as in my case.
Can anyone give me a hint how this would work?
Thanks a lot!
____________________________________________________________________
Lean Back and Relax - Enjoy some Nature Photography
http://photoblog.la-famille-schwarzer.de
Appetite for Global Data? UNEP GEO Data Portal:
http://geodata.grid.unep.ch
____________________________________________________________________ |
|
Back to top |
|
Celeb Administrator
Joined: 17 Apr 2007 Posts: 1025 Location: Vienna
|
Posted: Mon Dec 29, 2008 8:47 am Post subject: |
|
|
A 2-dimensional associative array suffices:
Code: | array(
array(
'name' => '...',
'short' => '...',
'link' => '...'),
array(
'name' => '...',
'short' => '...',
'link' => '...'),
array(
'name' => '...',
'short' => '...',
'link' => '...')
); |
Code: | {foreach from=$myArray item=foo}
<a href="{$foo.link}" title="{$foo.name}">{$foo.short}</a>
{/foreach} |
_________________ Darn computers always do what I tell them to instead of what I want them to do. |
|
Back to top |
|
luftikus143 Smarty Rookie
Joined: 14 Apr 2008 Posts: 8
|
Posted: Mon Dec 29, 2008 10:40 am Post subject: |
|
|
Thanks a lot.
Just for completion, here is how it worked for me:
Code: | {foreach from=$top_links key=k item=foo}
<li style="width: {$top_links_width}%"><a class="linksWhite" href="{$foo.url}" target="_blank" title="{$foo.name}">{$foo.short}</a></li>
{/foreach}
|
|
|
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
|