0

我正在构建 plone 5 主题,并且有一个关于使用 rules.xml 替换嵌套 html 元素的问题。请查看结构,然后阅读最后的问题。

Plone5主题文件结构

index.html 页脚.html header.html
header_1.html header_2.html rules.xml



索引.html

这是我的默认主题页面。我必须 div 我希望它们被其他元素替换。
我在 rules.xml 中这样做。

 ...
 <body>
    <div id="header"/>
    <div>my content. does not need to be replaced. static</div>
    <div id="footer"/>
 </body>
 ...

页脚.html

 <div id="footer">
   <div>This is your footer</div>
 </div>

header.html

 <div id="header">
   <div>This is your header</div>
   <div id="header_1"/>
   <div id="header_2"/>
 </div>

header_1.html

 <div id="header_1">
   <div>This is part 1 of your header</div>
 </div>

header_2.html

 <div id="header_2">
   <div>This is part 2 of your header</div>
 </div>

规则.xml

 <rules
    xmlns="http://namespaces.plone.org/diazo"
    xmlns:css="http://namespaces.plone.org/diazo/css"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <!-- in here I am replacing the footer. this works because there is not other elements inside 
    footer.html that needs to be replaced. -->
    <replace
     href="path/to/footer.html"
     css:theme="#footer"
     css:content="#footer"
     method="document"
    /> 

    *** 
     RULE FOR REPLACING
     header
        header_1
        header_2

</rules>

问题

  • 如何为标题编写替换规则以首先替换作为标题的父级,然后在标题父级中替换 header_1 和 header_2。

  • 我尝试了不同的方法来做到这一点,但我无法替换 header.html 中的元素。

  • 基本上,rules.xml 具有加载标头并替换其元素,然后查看是否将规则应用于刚刚替换的元素。

4

1 回答 1

0

我认为这行不通。您需要使用 theme="index.html" 定义一个模板,并且 diazo 编译器将在其中构建 xslt 规则。然后您可以使用规则从 Plone 获取内容,甚至可以使用 href 属性从不同的 url 获取内容。使用内联规则,您可以将部分注入到您的主题中,或者更好的是,您可以删除不需要的部分。因此,我会将您的页眉/页脚变体放入主题模板中,并使用条件删除规则将其清除。您还可以根据当前路径或内容方面的其他选择器使用不同的主题模板。在 Plone 中,您在 body 标记中有有用的 css 类。

于 2021-07-10T06:17:51.283 回答