在 Sulu 模板中包含带有 xpointer 的属性

我已经设置了一些 Sulu 模板,并且能够使用此处描述的方法将整个文件的内容包含在多个模板中:

https://docs.sulu.io/en/2.1/book/templates.html

我在用着:

<xi:include href="fragments/common-properties.xml"/

这很有效

不过,我随后尝试使用 xpointer 方法包含另一个模板中的属性(以便我可以在一个文件中包含所有模板中的一堆通用属性,另外还为各个模板定义特定属性)

我的根模板在这里:(root-page-test.xml)

<?xml version="1.0" ?>

<template xmlns="http://schemas.sulu.io/template/template"

          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xmlns:xi="http://www.w3.org/2001/XInclude"

          xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.0.xsd">


    <key>my-account-page-react</key>


    <view>pages/my-account-page-react</view>

    <controller>App\Controller\Headless\HeadlessWebsiteController::indexAction</controller>

    <cacheLifetime>604800</cacheLifetime>


    <meta>

        <title>Test including properties</title>

    </meta>

    

    <properties>

        <property name="header" type="text_line">

            <meta>

                <title>Header</title>

            </meta>

        </property>


        <xi:include href="include.xml"

            xpointer="xmlns(sulu=http://schemas.sulu.io/template/template)

                      xpointer(/sulu:properties/sulu:property)"/>


    </properties>

    

    


    

</template>


包含我想要包含的属性的模板位于此处:(include.xml)


<?xml version="1.0" ?>

<template xmlns="http://schemas.sulu.io/template/template"

          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xmlns:xi="http://www.w3.org/2001/XInclude"

          xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.1.xsd">


    <key>include-test</key>

    

    <view>pages/my-account-page-react</view>

    <controller>App\Controller\Headless\HeadlessWebsiteController::indexAction</controller>

    <cacheLifetime>604800</cacheLifetime>

    

    <meta>

        <title>Test include</title>

    </meta>


两个文件位于同一目录中


我哪里出错了?


翻翻过去那场雪
浏览 77回答 2
2回答

慕侠2389804

您的 XPointer 不正确,因为如果您以 a 开头,/则意味着您正在从文档的根目录开始。因此,如果您这样做,/sulu:properties/sulu:propertyXPointer 会假定properties您尝试包含的文件的根目录应该有一个标签。我的建议是您创建一个类似的文件(这也显示在本标题文档中的最后一个代码片段中):<?xml version="1.0" ?><properties xmlns="http://schemas.sulu.io/template/template"            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"            xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.1.xsd">    <property name="url" type="resource_locator" mandatory="true">        <meta>            <title>Resourcelocator</title>        </meta>        <tag name="sulu.rlp"/>    </property>            <property name="title" type="text_line" mandatory="true">         <meta>            <title>Title</title>         </meta>        <params>           <param name="headline" value="true"/>         </params>        <tag name="sulu.rlp.part"/>    </property>    <property name="article" type="text_editor">        <meta>            <title>Article</title>        </meta>    </property></properties>通过这种方式,您还可以删除不必要的元素,例如view和controller标签,在本例中不需要这些元素。或者,您也可以调整包含的 XPointer:<xi:include href="include.xml" xpointer="xmlns(sulu=http://schemas.sulu.io/template/template)xpointer(/sulu:template/sulu:properties/sulu:property)" />sulu:template注意xpointer 开头的附加内容。

动漫人物

我有同样的错误消息。但就我而言,这是 xpointer 定义中的语法错误。我写<xi:include&nbsp; &nbsp;href="default.xml"&nbsp; &nbsp;xpointer="xmlns(sulu=http://schemas.sulu.io/template/template)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xpointer(/sulu:template/sulu:properties/sulu:property"/><!-- _____________________________________________________________^ -->不知何故,我忘记了 xpointer 属性末尾的右括号。
打开App,查看更多内容
随时随地看视频慕课网APP