Alex B Alex B - 3 months ago 20
Smarty Question

smarty foreach attribute name not working

Does the syntax

name=foo_{$_id}


is correct? This syntax is not my concept.

<html>
<head>
<title>Smarty</title>
</head>
<body>
{foreach from=$pages key=m item=i name=foo_{$_id}}

{/foreach}
</body>
</html>


Because I get an error:

[13-Aug-2016 17:30:01 ...] PHP Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "file:/././././././././test.tpl" on line 36 "{foreach from=$test.params.rows key="rowId" item="rowText" name="rows_{$id}"}" 'name' attribute/variable has illegal value <--
thrown in /./././././smarty-3.1.29/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 36

Answer

Try:

{foreach from=$pages key=m item=i name="foo_`$_id`"}