Re: [SMARTY] problems with looping

From: Date: Fri, 19 Dec 2003 21:35:55 +0000
Subject: Re: [SMARTY] problems with looping
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10731@lists.php.net to get a copy of this message
Bill Shupp wrote:
Hello, I'm a new Smarty user, and am having problems displaying an associative array within a loop. Here's the section: {section name=row loop=$out_array}
    <tr bgcolor=#eeeeee>
            <td><a href="{$out_array[row].edit_url}">{$out_array[row].domain}</td>
            <td width=1% nowrap>{$out_array[row].status}</td>
            <td width=1% align=middle nowrap>
            {if $out_array[row].change_owner_url != ""}
                <a href="{$out_array[row].change_owner_url}">{$out_array[row].owner_name}</a>
            {else}
                {$out_array[row].owner_name}
            {/if}
            </td>
            <td width=1% align=middle nowrap>
            {if $out_array[row].change_owner_url != ""}
                <a href="{$out_array[row].change_owner_url}">{$out_array[row].group_owner_name}</a> 
            {else}
                {$out_array[row].group_owner_name}
            {/if}
            </td>
            <td width=1% align=middle>
            {strip}
            {if $out_array[row].status == "active"}
                {if $out_array[row].deactivate_url != ""}
                    <a href="{$out_array[row].deactivate_url}">de-activate</a>
                {else}
                    de-activate
                {/if}
            {else if $out_array[row].state == "inactive"}
                {if $out_array[row].activate_url != ""}
                    <a href="{$out_array[row].activate_url}">activate</a>
                {else}
                    activate
                {/if}
            {/if}
            {/strip}
            </td>
            <td align=middle width=1%><a href="{$out_array[row].delete_url}"><img src=images/trash.png border=0></a></td>
            </tr>
        {/section}
But the problem is that the *first* element of the array does not display values. The table row is there, but everything is blank. If I just output the array's values to the screen with this: {foreach from=$out_array item=theValue key=theKey} {$theKey}:{$theValue}<br>
    {foreach from=$theValue item=thenewValue key=thenewKey}
    <ul>
        <li>{$thenewKey}:{$thenewValue}<br>
    </ul>
    {/foreach}
{/foreach} The values are all there, so I'm confident that the array is being built properly, and assigned to Smarty successfully. Any idea why the first row would not display values in the {section} above?
Using {foreach} instead of {section} works, so I'll just use that. Regards, Bill

« previous php.smarty.general (#10731) next »