Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mustache Partials not found #49

Open
JonasHiltl opened this issue Nov 2, 2024 · 1 comment
Open

Mustache Partials not found #49

JonasHiltl opened this issue Nov 2, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@JonasHiltl
Copy link

I tried creating my own email template using mustache and want to create a template.mustache partial which is the base for all the other emails. But when testing the email I get the error:

com.github.mustachejava.MustacheNotFoundException: Template html/template.mustache not found

Doe keycloak-themes support partials?

Here are my theme files:

html/template.mustache:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title></title>
  </head>
  <body>
    {{ $content }}
  </body>
</html>

html/email-test.mustache:

{{< template }}
{{$ content}}
    </p>This is a test message. Customized by Jonas.</p>
    </p>Realm: {{realmName}}</p>
    {{#user}}
    </p>Username: {{user.username}}</p>
    </p>Email: {{user.email}}</p>
    </p>FirstName: {{user.firstName}}</p>
    </p>LastName: {{user.lastName}}</p>
    {{/user}}
{{/ content}}
{{/ template }}

Stack Trace:

2024-11-02 19:43:46 2024-11-02 18:43:46,545 INFO  [io.phasetwo.keycloak.themes.theme.FreeMarkerAndMustacheEmailTemplateProviderFactory] (executor-thread-1) creating new FreeMarkerAndMustacheEmailTemplateProviderFactory
2024-11-02 19:43:46 2024-11-02 18:43:46,548 INFO  [io.phasetwo.keycloak.themes.theme.FreeMarkerAndMustacheEmailTemplateProvider] (executor-thread-1) processTemplate for email-test.ftl in theme ocl
2024-11-02 19:43:46 2024-11-02 18:43:46,548 INFO  [io.phasetwo.keycloak.themes.theme.MustacheProvider] (executor-thread-1) templateType=mustache
2024-11-02 19:43:46 2024-11-02 18:43:46,548 INFO  [io.phasetwo.keycloak.themes.theme.MustacheProvider] (executor-thread-1) Trying mustache template at text/email-test.mustache
2024-11-02 19:43:46 2024-11-02 18:43:46,549 INFO  [io.phasetwo.keycloak.themes.theme.MustacheProvider] (executor-thread-1) Trying mustache template at html/email-test.mustache
2024-11-02 19:43:46 2024-11-02 18:43:46,549 INFO  [io.phasetwo.keycloak.themes.theme.FreeMarkerAndMustacheEmailTemplateProvider] (executor-thread-1) Using mustache template for email-test.ftl in theme ocl
2024-11-02 19:43:46 2024-11-02 18:43:46,560 INFO  [io.phasetwo.keycloak.themes.theme.MustacheProvider] (executor-thread-1) templateName: text/email-test.mustache, themeName: ocl, url: file:/opt/keycloak/bin/../themes/ocl/email/text/email-test.mustache
2024-11-02 19:43:46 2024-11-02 18:43:46,563 INFO  [io.phasetwo.keycloak.themes.theme.MustacheProvider] (executor-thread-1) templateName: html/email-test.mustache, themeName: ocl, url: file:/opt/keycloak/bin/../themes/ocl/email/html/email-test.mustache
2024-11-02 19:43:46 org.keycloak.email.EmailException: Failed to template email
2024-11-02 19:43:46     at io.phasetwo.keycloak.themes.theme.FreeMarkerAndMustacheEmailTemplateProvider.processMustacheTemplate(FreeMarkerAndMustacheEmailTemplateProvider.java:108)
2024-11-02 19:43:46     at io.phasetwo.keycloak.themes.theme.FreeMarkerAndMustacheEmailTemplateProvider.processTemplate(FreeMarkerAndMustacheEmailTemplateProvider.java:41)
2024-11-02 19:43:46     at org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.sendSmtpTestEmail(FreeMarkerEmailTemplateProvider.java:126)
2024-11-02 19:43:46     at org.keycloak.services.resources.admin.RealmAdminResource.testSMTPConnection(RealmAdminResource.java:1014)
2024-11-02 19:43:46     at org.keycloak.services.resources.admin.RealmAdminResource$quarkusrestinvoker$testSMTPConnection_0bc3cac9c894e7b29eb4c1f2d80a099cba7bdf38.invoke(Unknown Source)
2024-11-02 19:43:46     at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
2024-11-02 19:43:46     at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
2024-11-02 19:43:46     at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
2024-11-02 19:43:46     at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:582)
2024-11-02 19:43:46     at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
2024-11-02 19:43:46     at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
2024-11-02 19:43:46     at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
2024-11-02 19:43:46     at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
2024-11-02 19:43:46     at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
2024-11-02 19:43:46     at java.base/java.lang.Thread.run(Thread.java:1583)
2024-11-02 19:43:46 Caused by: org.keycloak.email.EmailException: Failed to template html email.
2024-11-02 19:43:46     at io.phasetwo.keycloak.themes.theme.FreeMarkerAndMustacheEmailTemplateProvider.processMustacheTemplate(FreeMarkerAndMustacheEmailTemplateProvider.java:103)
2024-11-02 19:43:46     ... 14 more
2024-11-02 19:43:46 Caused by: org.keycloak.theme.FreeMarkerException: Error processing mustache template html/email-test.mustache
2024-11-02 19:43:46     at io.phasetwo.keycloak.themes.theme.MustacheProvider.processTemplate(MustacheProvider.java:36)
2024-11-02 19:43:46     at io.phasetwo.keycloak.themes.theme.FreeMarkerAndMustacheEmailTemplateProvider.processMustacheTemplate(FreeMarkerAndMustacheEmailTemplateProvider.java:101)
2024-11-02 19:43:46     ... 14 more
2024-11-02 19:43:46 Caused by: com.github.mustachejava.MustacheNotFoundException: Template html/template.mustache not found
2024-11-02 19:43:46     at com.github.mustachejava.DefaultMustacheFactory.getReader(DefaultMustacheFactory.java:120)
2024-11-02 19:43:46     at com.github.mustachejava.MustacheParser.compile(MustacheParser.java:33)
2024-11-02 19:43:46     at com.github.mustachejava.DefaultMustacheFactory.compilePartial(DefaultMustacheFactory.java:248)
2024-11-02 19:43:46     at com.github.mustachejava.codes.ExtendCode.init(ExtendCode.java:82)
2024-11-02 19:43:46     at com.github.mustachejava.codes.DefaultCode.init(DefaultCode.java:124)
2024-11-02 19:43:46     at com.github.mustachejava.codes.DefaultMustache.init(DefaultMustache.java:70)
2024-11-02 19:43:46     at com.github.mustachejava.DefaultMustacheFactory.compile(DefaultMustacheFactory.java:192)
2024-11-02 19:43:46     at com.github.mustachejava.DefaultMustacheFactory.compile(DefaultMustacheFactory.java:186)
2024-11-02 19:43:46     at io.phasetwo.keycloak.themes.theme.MustacheProvider.processTemplate(MustacheProvider.java:30)
2024-11-02 19:43:46     ... 15 more
2024-11-02 19:43:46 2024-11-02 18:43:46,567 ERROR [org.keycloak.services.resources.admin.RealmAdminResource] (executor-thread-1) Failed to send email 
2024-11-02 19:43:46  org.keycloak.email.EmailException: Failed to template html email.
2024-11-02 19:43:46 2024-11-02 18:43:46,567 DEBUG [WebApplicationException] (executor-thread-1) Restarting handler chain for exception exception: org.keycloak.services.ErrorResponseException: HTTP 500 Internal Server Error
2024-11-02 19:43:46     at org.keycloak.services.ErrorResponse.error(ErrorResponse.java:43)
2024-11-02 19:43:46     at org.keycloak.services.ErrorResponse.error(ErrorResponse.java:36)
2024-11-02 19:43:46     at org.keycloak.services.resources.admin.RealmAdminResource.testSMTPConnection(RealmAdminResource.java:1018)
2024-11-02 19:43:46     at org.keycloak.services.resources.admin.RealmAdminResource$quarkusrestinvoker$testSMTPConnection_0bc3cac9c894e7b29eb4c1f2d80a099cba7bdf38.invoke(Unknown Source)
2024-11-02 19:43:46     at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
2024-11-02 19:43:46     at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
2024-11-02 19:43:46     at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
2024-11-02 19:43:46     at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:582)
2024-11-02 19:43:46     at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
2024-11-02 19:43:46     at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
2024-11-02 19:43:46     at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
2024-11-02 19:43:46     at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
2024-11-02 19:43:46     at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
2024-11-02 19:43:46     at java.base/java.lang.Thread.run(Thread.java:1583)
2024-11-02 19:43:46 
@xgp
Copy link
Member

xgp commented Nov 3, 2024

Doe keycloak-themes support partials?

No idea. Feel free to look at the code and submit a PR.

@xgp xgp added enhancement New feature or request help wanted Extra attention is needed labels Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants