FFFF Add overridable login header, aside, alert, and language macros by edewit · Pull Request #55265 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
4 changes: 4 additions & 0 deletions docs/documentation/release_notes/topics/27_0_0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ The welcome page shares the `keycloak.v3` login theme's layout, form controls, b

Realms that explicitly used `keycloak.v2` are migrated to `keycloak.v3` during upgrade. If you maintain a custom login theme based on `keycloak.v2`, or a custom welcome theme based on PatternFly 5, see the link:{upgradingguide_link}[{upgradingguide_name}] for migration steps.

== Login theme chrome macros

Custom login themes can override `header.ftl`, `aside.ftl`, `footer.ftl`, `alert.ftl`, and `language-selector.ftl` to customize brand content, a side panel for marketing or help text, the login-card footer, alerts, and the locale selector without replacing the full page layout.

== OID4VP verifier infers the DCQL query from mappers (experimental)

The OID4VP identity provider no longer requires a hand-written DCQL query.
Expand Down
13 changes: 13 additions & 0 deletions docs/documentation/upgrading/topics/changes/changes-27_0_0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,19 @@ The previous Base login templates are no longer provided.
Custom login themes with `parent=base` now inherit the new markup.
Review and update their template overrides and CSS to match the new structure.

==== Login header, aside, and alert macros

The Base login layout now exposes additional overridable macros so custom themes can change chrome without copying `template.ftl`:

* `header.ftl` — brand content above the login card
* `aside.ftl` — optional side panel next to the login card for marketing or help text (empty by default)
* `alert.ftl` — feedback alerts
* `language-selector.ftl` — locale dropdown

`footer.ftl` continues to provide the login-card footer.
When `aside.ftl` renders content, `keycloak.v3` uses a two-column layout on wide viewports.
See the UI customization guide for examples.

=== Auto-linking requires a trusted email (CVE-2026-97175)

Identity provider auto-linking now blocks the link when the IdP email is not verified and *Trust Email* is not enabled on the identity provider.
Expand Down
50 changes: 47 additions & 3 deletions docs/guides/ui-customization/themes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,31 @@ Or to use directly in HTML templates add the following to a custom HTML template
<img src="${r"${url.resourcesPath}"}/img/image.jpg" alt="My image description">
----

[[_theme_custom_footer]]
=== Adding a custom footer to a login theme
[[_theme_custom_login_chrome]]
=== Customizing login header, aside, and footer

The common login layout (`template.ftl`) renders three optional chrome macros that custom themes can override without copying the whole page shell:

* `header.ftl` — brand content above the login card (realm name / logo by default)
* `aside.ftl` — side panel next to the login card (empty by default; useful for marketing or help text)
* `footer.ftl` — content at the bottom of the login card (empty by default)

In order to use a custom footer, create a `footer.ftl` file in your custom login theme with the desired content.
Each file declares a `content` macro. Create the same file in your custom login theme to replace the default.
The `aside.ftl` and `footer.ftl` macros take no parameters.
The `header.ftl` macro must accept a `brandName` parameter, because `template.ftl` passes the realm display name as a named argument.

An example for a custom `header.ftl` may look like this:

[source]
----
<#noparse>
<#macro content brandName>
<div id="kc-header-wrapper" class="${properties.kcLoginBrand!}">
${kcSanitize(msg("loginTitleHtml", brandName))?no_esc}
</div>
</#macro>
</#noparse>
----

An example for a custom `footer.ftl` may look like this:

Expand All @@ -322,6 +343,29 @@ An example for a custom `footer.ftl` may look like this:
</#noparse>
----

An example for a custom `aside.ftl` may look like this:

[source]
----
<#noparse>
<#macro content>
<div>
<h2>Welcome</h2>
<p>Sign in with your organization account to continue.</p>
</div>
</#macro>
</#noparse>
----

When `aside.ftl` outputs content, the `keycloak.v3` theme switches to a two-column layout on wide viewports so the side panel appears next to the login card.

You can also override `alert.ftl` and `language-selector.ftl` to customize feedback alerts and the locale dropdown without replacing `template.ftl`.

[[_theme_custom_footer]]
=== Adding a custom footer to a login theme

See <<_theme_custom_login_chrome>> for customizing the login footer, header, and aside panel.

=== Adding an image to an email theme

To make images available to the theme add them to the `<THEME TYPE>/email/resources/img` directory of your theme. These can be used from within directly in HTML templates.
Expand Down
12 changes: 12 additions & 0 deletions themes/src/main/resources/theme/base/login/alert.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<#-- Render a login feedback alert with <@alert.alert message=message/>. -->
<#macro alert message>
<div class="${properties.kcAlertClass!} ${properties['kcAlert' + message.type?cap_first + 'Class']!}">
<div class="${properties.kcAlertIconClass!}">
<#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>
</div>
<span class="${properties.kcAlertTitleClass!} kc-feedback-text">${message.summary}</span>
</div>
</#macro>
4 changes: 4 additions & 0 deletions themes/src/main/resources/theme/base/login/aside.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<#-- Override content in aside.ftl to add marketing or help text beside the login card. -->
<#macro content>
<#-- The side panel next to the login box. Empty by default; override this file in your custom theme. -->
</#macro>
5 changes: 5 additions & 0 deletions themes/src/main/resources/theme/base/login/header.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<#-- Override content in header.ftl to customize the brand area above the login card. -->
<#macro content brandName=(realm.displayNameHtml)!''>
<div id="kc-header-wrapper"
class="${properties.kcLoginBrand!}">${kcSanitize(msg("loginTitleHtml",brandName))?no_esc}</div>
</#macro>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<#-- Render the locale dropdown with <@languageSelector.select/> when multiple locales are enabled. -->
<#macro select>
<#if ((realm.internationalizationEnabled)!false) && locale.supported?size gt 1>
<div class="${properties.kcLoginMainHeaderUtilities!}">
<div class="${properties.kcInputClass!}">
<select
aria-label="${msg("languages")}"
id="login-select-toggle"
(this.value) window.location.href=this.value"
>
<#list locale.supported?sort_by("label") as l>
<option
value="${l.url}"
${(l.languageTag == locale.currentLanguageTag)?then('selected','')}
>
${l.label}
</option>
</#list>
</select>
<span class="${properties.kcFormControlUtilClass!}">
<span class="${properties.kcFormControlToggleIcon!}">
<svg
class="${properties.kcSvgIconClass!}"
viewBox="0 0 320 512"
fill="currentColor"
aria-hidden="true"
role="img"
width="1em"
height="1em"
>
<path
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
>
</path>
</svg>
</span>
</span>
</div>
</div>
</#if>
</#macro>
60 changes: 11 additions & 49 deletions themes/src/main/resources/theme/base/login/template.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<#import "alert.ftl" as loginAlert>
<#import "aside.ftl" as loginAside>
<#import "field.ftl" as field>
<#import "footer.ftl" as loginFooter>
<#import "header.ftl" as loginHeader>
<#import "language-selector.ftl" as languageSelector>
<#import "theme-resources.ftl" as themeResourceTags>
<#-- Render the attempted username and restart-login action with <@layout.username/>. -->
<#macro username>
Expand Down Expand Up @@ -36,6 +40,7 @@
<#macro pageLayout bodyClass="" displayInfo=false displayMessage=true displayRequiredFields=false
bodyPageId="login-${pageId}" brandName=(realm.displayNameHtml)!'' pageTitle=(title!'')
headerDescription="" displayMain=true>
<#local asideHtml><@loginAside.content/></#local>
<!DOCTYPE html>
<html class="${properties.kcHtmlClass!}" lang="${lang}"<#if (realm.internationalizationEnabled)!false> dir="${(locale.rtl)?then('rtl','ltr')}"</#if>>

Expand Down Expand Up @@ -167,8 +172,7 @@
<div class="${properties.kcLogin!}">
<div class="${properties.kcLoginContainer!}">
<header id="kc-header" class="${properties.kcLoginHeader!}">
<div id="kc-header-wrapper"
class="${properties.kcLoginBrand!}">${kcSanitize(msg("loginTitleHtml",brandName))?no_esc}</div>
<@loginHeader.content brandName=brandName/>
</header>
<#if displayMain>
<main class="${properties.kcLoginMain!}">
Expand All @@ -177,44 +181,7 @@
<#if headerDescription?has_content>
<p class="${properties.kcLoginMainHeaderDescription!}">${headerDescription}</p>
</#if>
<#if ((realm.internationalizationEnabled)!false) && locale.supported?size gt 1>
<div class="${properties.kcLoginMainHeaderUtilities!}">
<div class="${properties.kcInputClass!}">
<select
aria-label="${msg("languages")}"
id="login-select-toggle"
(this.value) window.location.href=this.value"
>
<#list locale.supported?sort_by("label") as l>
<option
value="${l.url}"
${(l.languageTag == locale.currentLanguageTag)?then('selected','')}
>
${l.label}
</option>
</#list>
</select>
<span class="${properties.kcFormControlUtilClass!}">
<span class="${properties.kcFormControlToggleIcon!}">
<svg
class="${properties.kcSvgIconClass!}"
viewBox="0 0 320 512"
fill="currentColor"
aria-hidden="true"
role="img"
width="1em"
height="1em"
>
<path
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
>
</path>
</svg>
</span>
</span>
</div>
</div>
</#if>
<@languageSelector.select/>
</div>
<div class="${properties.kcLoginMainBody!}">
<#if !(auth?has_content && auth.showUsername() && !auth.showResetCredentials())>
Expand Down Expand Up @@ -251,15 +218,7 @@
<#-- App-initiated actions should not see warning messages about the need to complete the action -->
<#-- during login. -->
<#if displayMessage && message?has_content && (message.type != 'warning' || !isAppInitiatedAction??)>
<div class="${properties.kcAlertClass!} ${properties['kcAlert' + message.type?cap_first + 'Class']!}">
<div class="${properties.kcAlertIconClass!}">
<#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>
</div>
<span class="${properties.kcAlertTitleClass!} kc-feedback-text">${message.summary}</span>
</div>
<@loginAlert.alert message=message/>
</#if>

<#nested "form">
Expand Down Expand Up @@ -302,6 +261,9 @@
</div>
</main>
</#if>
<#if asideHtml?markup_string?trim?has_content>
<aside id="kc-aside" class="${properties.kcLoginAside!}">${asideHtml}</aside>
</#if>
</div>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@
"main"
}

/* Two-column layout when a custom aside.ftl provides side content */
.kc-login-aside {
align-self: center;
}

@media (min-width: 75rem) {
.pf-v6-c-login__container:has(.kc-login-aside) {
grid-template-columns: 34rem minmax(18rem, 34rem);
grid-template-areas: "header header"
"main aside";
max-width: none;
}

.kc-login-aside {
grid-area: aside;
}
}

.pf-v6-c-login__main {
border-top: 4px solid var(--keycloak-card-top-color);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ kcLogin=pf-v6-c-login
kcLoginContainer=pf-v6-c-login__container
kcLoginHeader=pf-v6-c-login__header
kcLoginBrand=pf-v6-c-brand
kcLoginAside=kc-login-aside pf-v6-c-content
kcLoginMain=pf-v6-c-login__main
kcLoginClass=pf-v6-c-login__main
kcLoginMainHeader=pf-v6-c-login__main-header
Expand Down
Loading
0