Best way to re-populate input field with Model data on front-end? I have a Plugin which saves data from a form the user enters on my front-end. When the input data is wrong and I display my validation errors using getErrors from the Model I want to re-populate all my form fields with the submitted data in my Twig template.

Right now I'm doing this like this:

&lt;input type="text" name="fieldName" value="{% if model is defined %}{{ model.fieldName}}{% endif %}"/&gt;


Is this the correct way of doing this or is there a better practice?

Seems like there's to many unnecessary if statements going on...

Thank you
The way the Craft docs do it is basically how you are already:

&lt;label for="userLastName"&gt;Last Name *&lt;/label&gt;
&lt;input id="userLastName" type="text" name="fields[userLastName]" {%- if entry is defined %} value="{{ entry.userLastName }}"{% endif -%}&gt;