在Smarty中组织链接

I would like to organize these links by categories; I've tried something but it doesn't work properly.

{if $mainResolutions|@count >0}
<ul>    
    {section name=item loop=$mainResolutions}
        {if $mainResolutions[item].enabled == 1}
            {assign var='res_name' value=$mainResolutions[item].width|cat:'x'|cat:$mainResolutions[item].height}
            <li><a href="{$res_name|url:'resolution'}">{$mainResolutions[item].width}x{$mainResolutions[item].height} {$mainResolutions[item].category}</a></li>
        {/if}
    {/section}  
</ul>   
{/if}

The above code will output HTML as follows:

<ul>
     <li><a href="/800x600-wallpapers-r.html">800x600 Normal 4:3</a></li>
     <li><a href="/1024x768-wallpapers-r.html">1024x768 Normal 4:3</a></li>
     <li><a href="/1152x864-wallpapers-r.html">1152x864 Normal 4:3</a></li>
     <li><a href="/1280x960-wallpapers-r.html">1280x960 Normal 4:3</a></li>
     <li><a href="/1400x1050-wallpapers-r.html">1400x1050 Normal 4:3</a></li>
     <li><a href="/1600x1200-wallpapers-r.html">1600x1200 Normal 4:3</a></li>
     <li><a href="/1920x1440-wallpapers-r.html">1920x1440 Normal 4:3</a></li>
     <li><a href="/1280x800-wallpapers-r.html">1280x800 Wide</a></li>
     <li><a href="/1440x900-wallpapers-r.html">1440x900 Wide</a></li>
     <li><a href="/1680x1050-wallpapers-r.html">1680x1050 Wide</a></li>
     <li><a href="/1920x1200-wallpapers-r.html">1920x1200 Wide</a></li>
     <li><a href="/2560x1600-wallpapers-r.html">2560x1600 Wide</a></li>
     <li><a href="/852x480-wallpapers-r.html">852x480 HD</a></li>
     <li><a href="/1280x720-wallpapers-r.html">1280x720 HD</a></li>
     <li><a href="/1366x768-wallpapers-r.html">1366x768 HD</a></li>
     <li><a href="/1920x1080-wallpapers-r.html">1920x1080 HD</a></li>
</ul>

While I would like the following:

<ul>
    <li><a href="#">Normal 4:3</a>
    <ul>
        <li><a href="/800x600-wallpapers-r.html">800x600 </a></li>
        <li><a href="/1024x768-wallpapers-r.html">1024x768 </a></li>
        <li><a href="/1152x864-wallpapers-r.html">1152x864 </a></li>
        <li><a href="/1280x960-wallpapers-r.html">1280x960 </a></li>
        <li><a href="/1400x1050-wallpapers-r.html">1400x1050 </a></li>
        <li><a href="/1600x1200-wallpapers-r.html">1600x1200 </a></li>
        <li><a href="/1920x1440-wallpapers-r.html">1920x1440 </a></li>
    </ul>
    </li>
    <li><a href="#">Wide</a>
    <ul>
        <li><a href="/1280x800-wallpapers-r.html">1280x800 </a></li>
        <li><a href="/1440x900-wallpapers-r.html">1440x900 </a></li>
        <li><a href="/1680x1050-wallpapers-r.html">1680x1050 </a></li>
        <li><a href="/1920x1200-wallpapers-r.html">1920x1200 </a></li>
        <li><a href="/2560x1600-wallpapers-r.html">2560x1600 </a></li>
    </ul>
    </li>
    <li><a href="#">HD</a>
    <ul>
        <li><a href="/852x480-wallpapers-r.html">852x480 </a></li>
        <li><a href="/1280x720-wallpapers-r.html">1280x720 </a></li>
        <li><a href="/1366x768-wallpapers-r.html">1366x768 </a></li>
        <li><a href="/1920x1080-wallpapers-r.html">1920x1080 </a></li>
    </ul>
    </li>
</ul>

Break your data into separate arrays in your php not in Smarty, then you can write 3 loops, or a sub loop

Try to get your Data to an Array like this

$MainResolutions = array('Normal 4:3' => array(item1 => array('name' =>'item1', enabled = 1, etc),
                         'Wide' => array(item1 => 'item1' etc),
                         'HD' => array(item1 => 'item1' etc));

$Smarty->assign('mainResolutions', $MainResolutions);

then your smarty can use foreach

{foreach from=$mainResolutions item=Resolution key=SectionName}
<ul>    
    {if Resolution.enabled == 1}

        <li><a href="{$SectionName}"> 
        {$Resolutions.width}x{$Resolution.height} {$Resolution.category}</a>
        </li>
    {/if}

{/foreach}

you can do it much much simpler using php arrays with all the info already organised, and then using foreach rather than sections.

I would suggest sorting the links in your mysql select or sort them in php so that you have a two denominational array

something like this

array(
     "normal" => array(
        ....
        ),
    "wide" => array(
    ....
    ),
    "HD" => array(
    ...
    )
)

then loop through them individually

or if there is already a property you can evaluate to decide when to make a new set with if statements that would work too

if you can show me what the array looks like before you output it to smarty i can help with the ifs

Keep your business logic separate from the presentation layer.
In your case, solution of task belongs to business logic.

Read this article: http://www.smarty.net/best_practices