-
Notifications
You must be signed in to change notification settings - Fork 493
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
Head include/substituteby improvement #3
Comments
A more general implementation of this could be to be able to define "insertions" to be injected into inserted fragments, for example by declaring placeholders for these insertions in the fragment, or even by simple appending/prepending contents. Queued for Thymeleaf 2.1 |
Great. Anyway thank you very much for Thymeleaf. It's really good template engine. |
I use a fragment such as <head>
<title th:text="${applicationName + ' : ' + title}">
...
</head> in my layout.html page, that I then include by way of <head th:substituteby="layout :: [//head]">head</head> but there is no way (that I can find) to specify the value of |
Variable substitution in a fragment works if you define the variable at a higher level. So, for your title example, you can do: <html xmlns=... th:with="title='hello'">
<head th:substituteby="layout::[//head]" /> I'm trying to include the contents of the head from another template and then add some additional scripts and links. I was trying something like: <head>
<link th:substituteby="layout::[//head]" th:remove="tag" />
<script src="@{/js/another.js}" />
</head> But then I find out the I also tried There is a way that works, but it's a little more cumbersome. In the template you're pulling from, tag the fragment multiple times: <head>
<link th:fragment="headcontent" ... />
<script th:fragment="headcontent" .../>
</head> Then, in the main template, just substitute the fragment once: <head>
<link th:substituteby="layout::headcontent" />
<script src="@{/js/another.js}" />
</head> |
Thanks @usethe4ce, that worked perfectly. I was using |
Still it would be really nice to have something more straight forward like the "insertions" described above, appending or prepending content to a tag element having a "th:include" or a "th:substituteby". Thanks for the work and the time invested |
I've written a dialect that currently performs these "insertions": create a parent 'layout' page, define points in the layout which will be overridden/filled-in by child/content pages, then reference the layout page in the child/content one (the one being processed by Thymeleaf). It also does a bunch of automatic insertions for the I don't know how far off Thymeleaf 2.1 would be, but for those looking for a solution now, would my dialect suffice? https://github.com/ultraq/thymeleaf-layout-dialect |
@ultraq Your dialect is very useful, thanks for sharing! |
Closing this issue for 2.1, as this is already offered by the LayoutDialect and 3.0 will include #180, which should solve this scenario for those not wanting to use this dialect for some reason. |
See #451 (Thymeleaf 3.0) |
Switch configuration to java base fixes
Hi it would be nice to have better way how to include/substituteby meta, link, script etc. in head element then one by one.
The text was updated successfully, but these errors were encountered: