如何使用th:block and th:包含在thymeleaf中?

Jes*_*sse 5 thymeleaf spring-boot

视觉

我的html其他页面位于编辑文件夹中.

我目前正在使用以下脚本

<!--/*/ <th:block th:include="fragments/header :: header"></th:block> /*/-->
Run Code Online (Sandbox Code Playgroud)

如果html文档位于同一目录中,则上述脚本有效.(例如; index.html能够读取片段).但我创建了一个新目录(名为:edit)来存储我的html页面.我需要退出当前文件夹,以便能够使用../找到片段文件夹

<!--/*/ <th:block th:include="../fragments/header :: header"></th:block> /*/-->
Run Code Online (Sandbox Code Playgroud)

但是这种方法不起作用.如何使用此语法退出文件夹?

ben*_*uly 7

看来您正在使用Spring Boot。Spring Boot自动配置Thymeleaf以查找中的所有HTML文件/templates

默认的application.properties中,您可以看到它:

spring.thymeleaf.prefix=classpath:/templates/
Run Code Online (Sandbox Code Playgroud)

因此(因为Thymeleaf /templates用作根)应该起作用:

<th:block th:include="fragments/header :: header"></th:block>
Run Code Online (Sandbox Code Playgroud)

和/或:

<th:block th:include="/fragments/header :: header"></th:block>
Run Code Online (Sandbox Code Playgroud)

您不需要“不需要离开当前文件夹”。