[prev in list] [next in list] [prev in thread] [next in thread]
List: smarty-general
Subject: [SMARTY] outputting a foreach in order
From: Vonleigh Simmons <nospam () illusionart ! com>
Date: 2004-02-16 7:30:44
Message-ID: 0829E79C-6052-11D8-8A0B-000A2791B6EC () illusionart ! com
[Download RAW message or body]
Hello,
I have a section of my site that builds up the navigation list. On the
bottom of this email you can find a sample array, the smarty code and
the output.
The array has a variable called position. The default is for position
not to be set. As it stands the foreach loop outputs the list in the
order in which it receives it (which is the order in which they were
put into the db).
However I'd like for smarty to output the list in the order in which
it receives it _except_ when the position is explicitly set. For
example a user could add a Home link and set it to position=1.
I'm not sure how exactly to do this and would appreciate any
suggestion you may have.
Vonleigh Simmons [vanlei]
San Francisco, CA
<www.illusionart.com/pi/>
Array
(
[Preferences] => Array
(
[id] => 2
[name] => Preferences
[type] => title
[value] =>
[position] =>
[children] => Array
(
[Personal Details] => Array
(
[id] => 1
[name] => Personal Details
[type] => preferences
[value] => personal_details/
[position] =>
[children] =>
)
)
)...
The smarty foreach that builds the list looks like so:
<ul>
{foreach name=category from=$userNavi key=catkey item=category}
{if $category.type eq "title"}
<li class="category">{$category.name}</li>
{else}
<li class="category"><a
href="{$category.value}">{$category.name}</a></li>
{/if}
{foreach name=subcategories from=$category.children
key=subcatkey item=subcategory}
<li class="subcategory"><a
href="{$subcategory.value}">{$subcategory.name}</a></li>
{/foreach}
{/foreach}
</ul>
The output is then:
<li class="category">Preferences</li>
<li class="subcategory"><a href="personal_details/">Personal
Details</a></li>
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic