keycloakfreemarkerkeycloak-serviceserror-messagingcustom-theme

Keycloak FTL: how can we access error messages within the login template on a custom theme


So I'm using keycloak as an authentication mechanism and customizing the login page by modifying the login.ftl file. So far so good. I'm importing the template.ftl file in my login.ftl - as instructed by keycloak's docs - so far so good. Within that template.ftl file - there's a way to access error messages as shown here

          <#if displayMessage && message?has_content && (message.type != 'warning' || !isAppInitiatedAction??)>
          <div class="alert alert-${message.type}">
              <#if message.type = 'success'><span class="${properties.kcFeedbackSuccessIcon!}"></span></#if>
              <#if message.type = 'warning'><span class="${properties.kcFeedbackWarningIcon!}"></span></#if>
              <#if message.type = 'error'><span class="${properties.kcFeedbackErrorIcon!}"></span></#if>
              <#if message.type = 'info'><span class="${properties.kcFeedbackInfoIcon!}"></span></#if>
              <span class="kc-feedback-text">${kcSanitize(message.summary)?no_esc}</span>
          </div>
      </#if>

Ok great! What if I don't want to handle the error message ui in that template.ftl file? I have a form UI on the login.ftl page that I'd like to display the error messages in. How can I either pass that message down to the login.ftl file OR access that error message from the login.ftl file? Thanks in advance for any guidance.


Solution

  • You can access it in login.ftl just like in template.ftl

    <#if message?has_content>
        message.summary
        ...
    </#if>
    

    I think you're having problem with template variables(displayMessage, isAppInitiatedAction) not being set in login.ftl