Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use th:block and th:include in thymeleaf?

Visual

My html other pages is in the edit folder.

I am currently using this script below

<!--/*/ <th:block th:include="fragments/header :: header"></th:block> /*/-->

Script above works if the html document is in the same directory. (Eg; index.html is able to read the fragments). But I created a new directory(named: edit) to store my html pages. I need to get out of the current folder so it would be able to find the fragment folder using ../

<!--/*/ <th:block th:include="../fragments/header :: header"></th:block> /*/-->

But this method does not work. How would I be able to exit out a folder using this syntax?

like image 228
Jodi Avatar asked Jan 11 '17 15:01

Jodi


1 Answers

It looks like you are using Spring Boot. Spring Boot autoconfigures Thymeleaf to find all HTML files in /templates.

In the default application.properties you can see it:

spring.thymeleaf.prefix=classpath:/templates/

So (because Thymeleaf uses /templates as root) that should work:

<th:block th:include="fragments/header :: header"></th:block>

And/or:

<th:block th:include="/fragments/header :: header"></th:block>

You don't "need to get out of the current folder".

like image 87
benkuly Avatar answered Sep 25 '22 15:09

benkuly