← Back to team overview

phpdevshell team mailing list archive

[Bug 687603] Re: Template file generating error for nested {foreach} loops

 

Ok wait a minute... this is NOT invalid.

But the problem actually has to do with cached smarty pages.

When you upload a new .tpl file sometimes the new file changes take
place immediately, sometimes the changes don't take place for a while,
and sometimes the changes generate an error like the one listed above.

When an error occurs, you have to re-upload the file again a second time
before leaving the error page and then it works properly. So in the
example above it says there is an unexpected {/foreach} but as soon as
the file (without changes) is uploaded a second time. The error goes
away.

-- 
You received this bug notification because you are a member of
PHPDevShell, which is subscribed to PHPDevShell.
https://bugs.launchpad.net/bugs/687603

Title:
  Template file generating error for nested {foreach} loops

Status in Open Source PHP RAD Framework with UI.:
  New

Bug description:
  Per Smarty documentation, foreach loops can be nested.

Assume an array as follows in the controller:
$RESULTS = array('1' => array('A','B'), '2' => array('C','D'), '3' => array('E','F') );
$view = $this->factory('views');
$view->set('RESULTS', $RESULTS);
$view->show();

This .tpl file works (no nested foreach):
<table>
    {foreach $RESULTS as $x}
        <tr>

                <td>{$x}</td>

        </tr>
    {foreachelse}
        No items found
    {/foreach}
</table>

This one does not:
<table>
    {foreach $RESULTS as $x}
        <tr>
            {foreach $x as $y}
                <td>{$x}:{$y}</td>
            {/foreach}
        </tr>
    {foreachelse}
        No items found
    {/foreach}
</table>

The above generated nested foreach loop give the following error:
Syntax Error in template "/home/mydomain/portal/plugins/phpYAerpContacts/views/add-new-contact.tpl" on line 14 " {/foreach} " unexpected closing tag





References