Unsure how error messages are referenced

I am new to Keylcloak UI development. I can understand most parts but not how error messages are referenced.

In my message_en.properties I have this message: ‘invalidUserMessage=Please enter a valid email.’

In my login.ftl I have the following:

<#if usernameEditDisabled??> <#else>
<#if messagesPerField.existsError('username','password')> ${kcSanitize(messagesPerField.getFirstError('username','password'))?no_esc} .....

If I enter an incorrect email the above error message appears under the <div class="extras" > part of my code. To be clear if I alter my message the change is reflected. My issues is that there is no reference of ‘invalidUserMessage’ outside of message property files so I cannot understand how the login.ftl knows to use this exact error message? There is no clear reference to it. There is no reference to it all anywhere in the file structure.

Also, when using the if else statements, is there any documentation on the commands I can use with them?

E.g. I have ’ <#if realm.loginWithEmailAllowed>’

What can work with the keyword realm and what other keywords can I use and how to use them? I am struggling to find any documentation on this.