【问题标题】:how to replace nested elements with diazo Rules.xml in Plone5如何在 Plone5 中用 diazo Rules.xml 替换嵌套元素
【发布时间】:2021-07-08 22:45:05
【问题描述】:

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

Plone5 主题文件结构

index.html
页脚.html
header.html
header_1.html
header_2.html
规则.xml

index.html

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

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

footer.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>

rules.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 具有加载标头并替换其元素,然后查看是否将规则应用于刚刚替换的元素。

【问题讨论】:

    标签: html xml rules diazo plone-5.x


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-24
      • 2022-06-15
      • 2019-03-25
      • 2014-08-13
      • 1970-01-01
      • 1970-01-01
      • 2018-04-18
      • 1970-01-01
      相关资源
      最近更新 更多