Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 胸腺内延伸片段_Spring Boot_Thymeleaf - Fatal编程技术网

Spring boot 胸腺内延伸片段

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”。。。但是呈现的页面只包含来自片段/头的标记,其中包含og标记

如何向片段添加更多标记

<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中可用。如果无法切换,可以尝试路径一些
映射
,而不是标记块。