[2.1dev] Latte {continueIf} macro behavior

Notice: This thread is very old.
Mysteria
Member | 797
+
0
-

Nette Framework 2.1dev (revision c0af0e6 released on 2013–05–20)

Latte code:

<?php
<tbody n:inner-foreach='$punishments as $punishment'>
	{continueIf !$punishment[active]}
	<tr>
		<td>{$punishment[id]}</td>
	</tr>
</tbody>
?>

Generated PHP code:

<?php
$iterations = 0; foreach ($punishments as $punishment): if (!$punishment['active']) { echo "</tbody>\n"; continue; }
?>

Generated HTML Code:

<?php
<tbody>
</tbody>
</tbody>
</tbody>
</tbody>
</tbody>
</tbody>
</tbody>
</tbody>
</tbody>
</tbody>
</tbody>
</tbody>
</tbody>
</tbody>
</tbody>
?>

Question is why {continueIf} macro always close that </tbody> tag? This generate bad HTML code.

I am not sure if this is bug, but when I open CoreMacros.php, line 259:

<?php
return $writer->write("if (%node.args) { echo \"</{$node->parentNode->htmlNode->name}>\\n\"; $cmd; }");
?>

and rewrite it to

<?php
return $writer->write("if (%node.args) { $cmd; }");
?>

{continueIf} not close </tbody> tag and generate good HTML code.

Last edited by Mysteria (2013-05-30 16:19)

voda
Member | 561
+
0
-

This was changed a month ago. Commit 5e31642, issue #884.

hrach
Member | 1834
+
0
-

This is IMO bug. It should behave so only for n:foreach, not for n:inner-foreach.

Last edited by hrach (2013-05-30 21:00)

David Grudl
Nette Core | 8117
+
0
-

fixed