I follow this guide: http://www.thymeleaf.org/doc/layouts.html (got into the timeline dialect section). There you can find an example:
<!DOCTYPE html> <html> <head> <title layout:title-pattern="$DECORATOR_TITLE - $CONTENT_TITLE">Task List</title> ... </head> <body> <div th:replace="fragments/header :: header"> ... </div> <div class="container"> <div layout:fragment="content"> ... </div> <div th:replace="fragments/footer :: footer">© 2014 The Static Templates</div> </div> </body> </html>
The footer and header are replaced with the th:replace tag in the above example, and the <head> has the <title> in the layout file.
Basically, I want to replace the <head> tag with the whole th:replace tag. Therefore, I have:
My layout file:
<!DOCTYPE html> <html> <head th:replace="/html/components/head :: head"> </head> <body> <div layout:fragment="content"> </div> ... <div th:replace="/html/components/footer :: footer" /> </body> <html>
My content file:
<!DOCTYPE html> <html layout:decorator="/html/layouts/layout"> <head> <title>My content title</title> </head> <body> <div layout:fragment="content"> ... </div> </body> </html>
And finally my file /html/components/head.htm:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> <head th:fragment="head"> <meta charset="utf-8" /> <title layout:title-pattern="$CONTENT_TITLE">Layout Title should be replaced by Content Title!</title> ... </head> <body> </body> </html>
Content is OK. The footer and head are included (replaced) from the files as expected, but the page title is empty!
I get:
<!DOCTYPE html> <head> <meta charset="utf-8" /> <title></title> ...
What's wrong?
source share