Smarty Template help

Permabanned
Joined
25 Oct 2004
Posts
9,078
Hiya,

Anyone familiar with smarty templates, im fairly new to it all and im trying to modify a template which lists categories.

At the moment the template just lists the categories in one large column, but i would like to split it up over 3 columns, limiting the number of entries to each column.

This is the code i have currently which lists them all in one column. How would I go about listing them across 3 columns, for example limiting each column to only 5 rows.

Code:
<table cellpadding="2" cellspacing="1" style="border-style: none; width: 100%;">

    {foreach from=$link_url key=id item=url}

        {if $open_col.$id eq 1}
            <tr>
        {/if}

        <td style="width:{$column_width}">

            {if $image.$id}
                <a href="{$url}" class='main_navigation_1_name'><img src='{$image.$id}' style="margin: 0px 2px; border-style: none; float: left;"></a>
            {/if}

            <a href="{$url}" class='main_navigation_1_name'>{$categories_name2.$id}</a>

            {* these display inline with the category name, but put them on their own lines for code-readability *}
            {$categories_display_count.$id}
            {if $new_icon.$id}{$new_icon.$id}{/if}
            
             
             {if $description.$id}<br /><span class="class_navigation_1_description">{$description.$id|fromDB}</span>{/if}
             {if $sub_categories_tpl.$id}<br />{$sub_categories_tpl.$id}{/if}
         </td>
        
        {if $close_col.$id eq 1}
            </tr>
        {/if}
    {/foreach}
    
</table>

Any help much appreciated
 
Not used smarty in years.

Looking at the code, I'm taking a big chance on a simple fix :)

PHP:
<table cellpadding="2" cellspacing="1" style="border-style: none; width: 100%;">

    {foreach from=$link_url key=id item=url}

        {if $open_col.$id eq 3}
            <tr>
        {/if}

        <td style="width:{$column_width}">

            {if $image.$id}
                <a href="{$url}" class='main_navigation_1_name'><img src='{$image.$id}' style="margin: 0px 2px; border-style: none; float: left;"></a>
            {/if}

            <a href="{$url}" class='main_navigation_1_name'>{$categories_name2.$id}</a>

            {* these display inline with the category name, but put them on their own lines for code-readability *}
            {$categories_display_count.$id}
            {if $new_icon.$id}{$new_icon.$id}{/if}
            
             
             {if $description.$id}<br /><span class="class_navigation_1_description">{$description.$id|fromDB}</span>{/if}
             {if $sub_categories_tpl.$id}<br />{$sub_categories_tpl.$id}{/if}
         </td>
        
        {if $close_col.$id eq 3}
            </tr>
        {/if}
    {/foreach}
    
</table>

This is just from skimming the code, quickly it looks like its using a variable each time to force a new line of a column ( $open_col.$id ) using the <tr> .... and closing the </tr> with ( $close_col.$id )

Changing this to 3 MAY give you the desired 3 columns. It also MAY **** everything up so make sure you do a backup and are not playing on a live site ;)

Its either this or you can define the open/close variables somewhere in the php code to 3 where it will currently be 1.
 
An edit on myself, you will probably have to leave the open line as 1 and edit the close tag as 3.

Without having the code to play with myself I can only pitch a few ideas, sorry
 
Back
Top Bottom