Getting to grips with errors and flash messages As a newbie to Craft and Craft Commerce. I wondered if someone could explain the difference between all these error codes that I have seen either in the docs, this forum or the templates and when they get set and when I should use each method in which situations? Apologies if this is a broad question...

{% if errors is defined %}
    &lt;ul class="errors"&gt;
        {% for error in errors %}
            &lt;li&gt;{{ error }}&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
{% endif %}


{% if errorMessage is defined %}
   &lt;p class="error"&gt;{{ errorMessage }}&lt;/p&gt;
{% endif %}

{% if model and model.getErrors('firstName') %}
   &lt;span class="error"&gt;{{ model.getErrors('firstName')|join }}&lt;/span&gt;
{% endif %}
It's hard to be more specific without some more context for each of the snippets you post, but:

{% if errors is defined %}
    &lt;ul class="errors"&gt;
        {% for error in errors %}
            &lt;li&gt;{{ error }}&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
{% endif %}


That's checking if a variable named errors has been passed into the template, and if so it assumes it's an array and loops through the array to display each error in an unordered list.

{% if errorMessage is defined %}
    &lt;p class="error"&gt;{{ errorMessage }}&lt;/p&gt;
{% endif %}


That's checking is a variable named errorMessage has been passed into the template and if so it assumes it's a string and just displays the single error message.

{% if model and model.getErrors('firstName') %}
   &lt;span class="error"&gt;{{ model.getErrors('firstName')|join }}&lt;/span&gt;
{% endif %}


That's checking if a variable named model has been passed into the template and assumes it's an instance of BaseModel.  Then it calls the getErrors method of the class passing in firstName as a parameter to specifically check if any errors have been set on its firstName attribute.  If so, it will take that array of errors and display them using Twig's join filter.