How to render form errors via Latte?

Notice: This thread is very old.
MartyIX
Member | 217
+
0
-

There's an example of rendering form in pure PHP and with the help of Latte engine: https://doc.nette.org/en/forms#…

The samples are almost identical but there's not written how to write in Latte this part:

	<?php $form->render('errors') ?>

How can it be done?

Thanks!

HosipLan
Moderator | 4668
+
0
-

There is no such macro. You can either go for {$form->render('errors')} which will always work, because macro {form} does define variable $form.

But those macros strictly don't use default form renderer. So it would be better to define own macro or render it like this

<ul class="errors" n:if="$form->hasErrors()">
	<li n:foreach="$form->errors as $error">{$error}</li>
</ul>

Last edited by HosipLan (2011-08-14 08:37)

MartyIX
Member | 217
+
0
-

Thanks!

uestla
Backer | 799
+
0
-

inner-foreach, am I right?

voda
Member | 561
+
0
-

A think inner-foreach is the right one and I would add an n:if="$form->hasErrors()" or you end up with an empty list.

Last edited by voda (2011-08-13 16:57)

HosipLan
Moderator | 4668
+
0
-

Ofcourse, you're right. I was writting it in a hurry :)

Last edited by HosipLan (2011-08-14 08:37)