Spring boot 胸腺内延伸片段
我有以下片段。我试图用开放图标记扩展基本片段“head”。。。但是呈现的页面只包含来自片段/头的标记,其中包含og标记 如何向片段添加更多标记Spring boot 胸腺内延伸片段,spring-boot,thymeleaf,Spring Boot,Thymeleaf,我有以下片段。我试图用开放图标记扩展基本片段“head”。。。但是呈现的页面只包含来自片段/头的标记,其中包含og标记 如何向片段添加更多标记 <head th:include="fragments/head :: head"> <!-- You can use Open Graph tags --> <meta property="og:url" th:content="${url}" /> <meta prop
<head th:include="fragments/head :: head">
<!-- You can use Open Graph tags -->
<meta property="og:url" th:content="${url}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="GUApp" />
<meta property="og:description" th:content="${description}" />
<!--<meta property="og:image" content="http://www.your-domain.com/path/image.jpg" />-->
</head>
<head th:fragment="head" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
....
</head>
....
最简单的方法是像文档演示一样传递附加标签
由于片段表达式,我们可以为
不是文本、数字、bean对象的片段…而是
标记的片段
这使我们能够以一种可以被复制的方式创建片段
使用来自调用模板的标记进行了丰富,从而
非常灵活的模板布局机制
index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:include="header :: head(~{::meta})">
<!-- You can use Open Graph tags -->
<meta property="og:url" th:content="${url}"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="GUApp"/>
<meta property="og:description" th:content="${description}"/>
</head>
...
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:fragment="head(meta)">
<!-- some default styles -->
<link href="base.css" rel="stylesheet" />
<!--/* Per-page placeholder for additional meta tags */-->
<th:block th:replace="${meta}" />
</head>
...
...
header.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:include="header :: head(~{::meta})">
<!-- You can use Open Graph tags -->
<meta property="og:url" th:content="${url}"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="GUApp"/>
<meta property="og:description" th:content="${description}"/>
</head>
...
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:fragment="head(meta)">
<!-- some default styles -->
<link href="base.css" rel="stylesheet" />
<!--/* Per-page placeholder for additional meta tags */-->
<th:block th:replace="${meta}" />
</head>
...
...
结果html:
<!DOCTYPE html>
<html lang="en">
<head>
<link href="base.css" rel="stylesheet" />
<meta property="og:url"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="GUApp"/>
<meta property="og:description"/>
</head>
...
...
它应该根据文档工作,但是。。。无法作为片段选择进行分析:“片段/head::head(~{::meta})”(concorso:4)@Progeny您正在使用Thymeleaf 2吗?因为我认为灵活的布局只在版本3中可用。如果无法切换,可以尝试路径一些映射
,而不是标记块。