使用XDV将类添加到body元素 [英] Adding an class to body element with XDV

查看:103
本文介绍了使用XDV将类添加到body元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Plone3 + collective.xdv中为某些表单设置样式,但是我不希望所有表单都具有特殊样式.

I want to style some forms in Plone3+collective.xdv but I don't want all forms to get the special style.

所以我想在显示某些模板时向body元素的class属性添加特殊的styled-form类名称:

So I'd like to add a special styled-form class name to the class attribute of the body element just when displaying certain templates:

  • 联系信息
  • sendto_form
  • PFG表格

所以我认为我可以设法用XDV执行此操作,以便不修改那些模板.

So I thought that I could manage to perform this with XDV in order not to modify those templates.

通过使用XDV规则中的if-content指令,我可以检查是否显示了这些模板:

By using the if-content directives in XDV rules I can check if those templates are being displayed:

css:if-content="body.template-contact-info"

例如

.

但是我没有找到方法来保持Plone提供的 class属性并根据该条件添加特殊的类.

But I don't find the way to keep the class attribute as delivered by Plone and add the special class based on that condition.

我想要的结果将是:

<body class="template-contact-info styled-form">
    ...
</body>

提前谢谢.

推荐答案

使用Diazo/plone.app.theming,您可以合并模板和内容中的属性,请参见:

With Diazo/plone.app.theming you can merge attributes from the template and content, see: http://diazo.org/basic.html#merge

如果您无法升级,则需要使用内联XSL进行此操作,例如:

If you can't upgrade then you'll need to do this with inline XSL, something like:

<prepend theme="/html/body" css:if-content="body.template-contact-info"><xsl:attribute name="class"><xsl:value-of select="/html/body/@class"/> styled-form</xsl:attribute></prepend>

更新:我在上面的示例中忘记了标签.现在应该可以使用了.

Update: I forgot the tag in the example above. It should work now.

这篇关于使用XDV将类添加到body元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆