[2.1dev] Latte {continueIf} macro behavior

Notice: This thread is very old.

7 years ago

Mysteria
Member | 774
+
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)

7 years ago

voda
Member | 562
+
0
-

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

7 years ago

hrach
Member | 1816
+
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)

7 years ago

David Grudl
Nette Core | 7067
+
0
-

fixed