collective.xdv and multiple theme files

若如初见. 提交于 2019-12-05 15:12:07

We usually just utilize plain xdv and use the rules.xml (or whatever you want to call it) file to setup the theme templates leaving the corresponding properties in the collective.xdv controlpanel empty. Nesting rules gives you quite some fexibility when asigning different templates:

<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://namespaces.plone.org/xdv"
   xmlns:css="http://namespaces.plone.org/xdv+css"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<theme css:if-content="body.section-front-page" href="frontpage.html" />
<theme css:if-path="/section/subsection/somefolder" href="somefolder.html" />
...
<rules css:if-content="#visual-portal-wrapper">
    <!-- The default theme -->
    <theme href="theme.html" />
    <rules css:if-content="body.section-somefolder">
        <!-- Secific rules for somefolder go here -->
        ...
    </rules>
</rules>

You should use the Alternate Themes settings to define alternative layouts when the url matches a specific regular expression.

For example, we have a Plone site named "Plone" and accessible at url localhost:8080/Plone. To provide a different layout for the Home page, we can define the following in the registry (or TTW in the Plone Control Panel > XDV Settings section):

<record field="alternate_themes" interface="collective.xdv.interfaces.ITransformSettings" name="collective.xdv.interfaces.ITransformSettings.alternate_themes">
    <field type="plone.registry.field.List">
        <description>Define alternate themes and rules files depending on a given path. Should be of a form 'path theme rules' (or 'path rules' with xdv 0.4), where path may use a regular expression syntax, theme is a file path or URL to the theme template and rule is a file path to the rules file.</description>
        <required>False</required>
        <title>Alternate themes</title>
        <value_type type="plone.registry.field.TextLine">
            <title>Theme</title>
        </value_type>
    </field>
    <value>
        <element>^.*/Plone(/)?$ python://my.xdvtheme/templates/alternative/index.html python://my.xdvtheme/rules/alternative/index-rules.xml</element>
    </value>
</record>

This way, the home page will use the alternative layout, while all the other pages will use the main layout specified in Theme template and Rules template

You can provide multiple definitions according to the different sections of your site.

My personal Plone site uses different theme and rules files for different parts.

Are you using the XDV control panel at /@@xdv-settings?

In the Theme template and Rules File fields I put my default (i.e most used) files.

In the Alternate Themes textbox you can then provide alternate theme and rules files depending on a given path.

The format is path theme rules.

Here are some examples from my website's config:

  1. .*/login_form|.*logged_out /home/zope/production/theme/theme.html /home/zope/production/theme/login.xml
  2. /media/blog$ /home/zope/production/theme/blog.html /home/zope/production/theme/blog.xml
  3. /media/software /home/zope/production/theme/software.html /home/zope/production/theme/media.xml

As you can see, you can use regular expression syntax to match the paths.

The first line is for styling the login and logout pages. The second for styling only my blog's landing page (henche the $) the third styles my software page.

Works like a charm.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!