[Themed view] fragment ignored

51 views
Skip to first unread message

Michele Melluso

unread,
Jan 14, 2019, 7:50:28 AM1/14/19
to CAS Community
Hi,

we're trying to customize the view as described in the following pages in cas 6.0 (but didn't manage even on 5.3.x):


our templates have been externalized and linked using the following properties:

spring.thymeleaf.prefix=file:///etc/cas/templates/
cas.view.templatePrefixes[0]=file:///etc/cas/templates

in /etc/cas/templates we cloned all the views (for Frontend Team editing) and added the same views, including fragments the folder:

/etc/cas/templates/mytheme

the theme is being recognized as css and casLoginView.html is rendered but fragment themed customization (eg. /etc/cas/templates/mytheme/fragments/loginform.html) is not recognized, since cas keeps rendering the main one (/etc/cas/templates/fragments/loginform.html).

I saw in documentation there is a "View vs Fragment" banner, but I cannot understand whether fragment theme customization is possible or not.

i found the following topic:

but it doesn't speak about fragments.

Thanks in advance
Michele

Andy Ng

unread,
Jan 16, 2019, 2:49:20 AM1/16/19
to CAS Community
Hi Michele,

For fragments, by default even if you are using theme, it will point to the main fragment.

This is because thymeleaf render path by attaching the path with the prefix, instead of using the one in the theme directory.



As you can see, fragment is called like this: <a href="fragments/cookies.html">cookies fragment</a>

Hence, even in themed login, it will still point to (in your case): /etc/cas/templates/ + fragments/cookies.html = /etc/cas/templates/fragments/cookies.html

My current work around is only to add back the themed name to casLoginView.html in the theme directory (e.g. <a href="mytheme/fragments/cookies.html">cookies fragment</a> ), there might be ways to make it modular but I am out of idea during that time.

See if the above help you!


Cheers!
- Andy

Michele Melluso

unread,
Jan 16, 2019, 3:26:49 AM1/16/19
to CAS Community
Hi Andy,

thank you for the reply. I successfully applied your suggestion.

The only difference is that I had to add the theme name in the th:replace tag instead of href

<div th:replace="mytheme/fragments/loginform :: loginform">
  <a href="fragments/loginform.html">Login Form goes here</a>
</div>

thanks again
Michele

Andy Ng

unread,
Jan 16, 2019, 3:32:51 AM1/16/19
to CAS Community
np, and your implementation seems clear too, nice :) - Andy
Reply all
Reply to author
Forward
0 new messages