Smarty3Dev foreachelse

10 views
Skip to first unread message

Abalam

unread,
Nov 5, 2009, 11:44:06 AM11/5/09
to Smarty Developers
Hi,

{foreachelse} does not work anymore ?

Thanks for reading,
Yann.

U.Tews

unread,
Nov 5, 2009, 11:50:57 AM11/5/09
to Smarty Developers
It does work. What sort of problem do you have?

Abalam

unread,
Nov 6, 2009, 3:52:27 AM11/6/09
to Smarty Developers
More details :

Exception: Syntax Error in template "/home/inventaire/core/templates/
inventaire/elmt_quick_insert.tpl.dialog" on line 29 " {foreachelse}"
unclosed {else} tag in /home/inventaire/core/libs/Smarty/sysplugins/
smarty_internal_templatecompilerbase.php on line 263


Here's the template :
<tbody>
{foreach from=$current_class->colonnes.quick_insert
key=key item=item}
<tr>
{if ATF::$html->template_exists("attr-{$key}-
update.tpl.htm")} {* Afin de pouvoir gérer un template particulier
pour un champ ! *}
{include file="attr-{$key}-update.tpl.htm" key=
$key item=$item}
{else}
{include file="generic_field.tpl.htm" key=$key
item=$item}
{/if}
</tr>
{foreachelse}
Aucun champs elmt->colonnes.primary
{/foreach}
</tbody>

Thanks for reading,
Yann

Abalam

unread,
Nov 6, 2009, 3:59:14 AM11/6/09
to Smarty Developers
After few experiments :
If we remove a line above, => {include file="button.tpl.htm"
text="valid"....
It works.

Do you made changes in { and " interpretation ?

Here's the complete tpl code :
<form name="elmt,insert" id="elmt,insert">
<table style="width:100%">
<tfoot>
<tr>
<td colspan="2">
<input type="hidden" name="elmt[id_parent]" id="elmt[id_parent]"
value="{$smarty.post.id_parent}" />
</td>
</tr>
<tr>
<td colspan="2">
<div class="submit" id="submit">
{include file="button.tpl.htm" text="valid" onclick=" ATF.insert
('elmt,insert' , { onComplete: function (e) { new ATF.tpl2div
('formulaire,addNewElmt.ajax,id_gep_projet=
{$smarty.post.id_gep_projet}', 'id_elmt='+e.result+'&id_gep_projet=
{$smarty.post.id_gep_projet}&id_parent={$smarty.post.id_pe_parent}');
Modalbox.hide(); ATF.adjustContainer(); } });"}
{include file="button.tpl.htm" text="retour"
icone="back" onclick="Modalbox.hide();"}
</div>
</td>
</tr>
</tfoot>
<tbody>
{foreach from=$current_class->colonnes.quick_insert
key=key item=item}
<tr>
{if ATF::$html->template_exists("attr-{$key}-
update.tpl.htm")} {* Afin de pouvoir gérer un template particulier
pour un champ ! *}
{include file="attr-{$key}-update.tpl.htm" key=
$key item=$item}
{else}
{include file="generic_field.tpl.htm" key=$key
item=$item}
{/if}
</tr>
{foreachelse}
Aucun champs elmt->colonnes.primary
{/foreach}
</tbody>
</table>
</form>


On 5 nov, 17:50, "U.Tews" <uwe.t...@googlemail.com> wrote:

U.Tews

unread,
Nov 8, 2009, 11:29:36 AM11/8/09
to Smarty Developers
I finally found it. The fix is in the SVN

Abalam

unread,
Nov 9, 2009, 3:21:30 AM11/9/09
to Smarty Developers
Hi,

I don't know the relation, but i just updated and now have this
error :

Erreur 1: Uncaught exception 'Exception' with message 'Syntax Error in
template "/home/inventaire/core/templates/menu.tpl.js" on line 19 " {*
Création récursive des sous menus *}" - Unexpected "* ", expected one
of: "'" , "{" , "boolean" , "null" , "(" , "[" , INTEGER , "+" , "-" ,
"$" , "#" , """ , "identifier" , TYPECAST , SINGLEQUOTESTRING in /home/
inventaire/core/libs/Smarty/sysplugins/
smarty_internal_templatecompilerbase.php on line 263

This part of my code is recursive...
It seems that comments with {* *} aren't parsed correctly.

Thanks for reading,
Yann

Abalam

unread,
Nov 9, 2009, 3:23:15 AM11/9/09
to Smarty Developers
FYI :

{* Création récursive des sous menus *}
{if $item.module=="my"}
{* blablabla *}

Yann

On 8 nov, 17:29, "U.Tews" <uwe.t...@googlemail.com> wrote:

U.Tews

unread,
Nov 9, 2009, 12:06:08 PM11/9/09
to Smarty Developers
This problem is fixed in the SVN now

Abalam

unread,
Nov 10, 2009, 3:28:22 AM11/10/09
to Smarty Developers
Seems to work,

Thanks.

Yann

dave B.

unread,
Nov 11, 2009, 9:56:48 AM11/11/09
to Smarty Developers
Err I just got a compile error with a simple foreachelse using
Smarty3Dev (r3325)
Problem with closing braces.

{foreach from=$list item=lisitem)
{$listitem}
(foreachelse)
No Items.
{/foreach}

I fixed the problem in @see patch but you may want to double check.

sysplugins/smarty_internal_compile_foreach.php patch:
@@ -154,7 +154,7 @@
list($_open_tag, $this->compiler->nocache) = $this->_close_tag
(array('foreach'));
$this->_open_tag('foreachelse',array('foreachelse', $this-
>compiler->nocache));

- return "<?php }} else { ?>";
+ return "<?php echo '<?php }} else { ?>'; ?>";
}
}

@@ -183,9 +183,9 @@
list($_open_tag, $this->compiler->nocache) = $this->_close_tag
(array('foreach', 'foreachelse'));

if ($_open_tag == 'foreachelse')
- return "<?php } ?>";
+ return "<?php echo '<?php } ?>'; ?>";
else
- return "<?php }} ?>";
+ return "<?php echo '<?php }} ?>' ?>";
}
}


dave B.

unread,
Nov 11, 2009, 10:10:41 AM11/11/09
to Smarty Developers
Sorry typo's in my sample template but that is not related to the
problem.
Should be.
{foreach from=$list item=listitem}
{$listitem}
{foreachelse}
No Items.
{/foreach}

U.Tews

unread,
Nov 11, 2009, 11:21:29 AM11/11/09
to Smarty Developers

Dave

Thanks for bringing this up. The compiler did compile wrong code for
{foreacheelse}, {forelse} and {sectionelse} when using nocache
variables.

But your patch is incorrect.

The correct fix is in the SVN now.
Reply all
Reply to author
Forward
0 new messages