michal.jakubeczy
michal.jakubeczy

Reputation: 9479

Thymeleaf - include template from the same directory (relative path)

I am currently including fragments in Thymeleaf templates by specifying full path to the fragment directory like this:

<div th:replace="/my/full/long/path/to/template.html :: main"></div>

The problem is paths are sometimes long due to the fact the application has many views separated in folders.

We are using following statement to use the current directory:

<div th:replace="__${execInfo.templateName}__/../template.html :: main"></div>

But this become deprecated in 3.0 version. Is there any way to use the current path of the currently processed template in included fragments.

I know I can use the template prefix, but this is not the solution as we're only prefixing by the root template directory. Also I do not want to put fragments to the same file as the template.

Upvotes: 1

Views: 1455

Answers (1)

Haggerty Rocks
Haggerty Rocks

Reputation: 11

I attempted something similar using Thymleaf 3.0.11, and this looks like it works -

<div th:replace="~{__${execInfo.templateName}__/../template.html :: main}"></div>

Upvotes: 1

Related Questions