collective.xdv and multiple theme files

465 views Asked by At

I am having different theme HTML files for different site sections. There are some major layout differences depending if the page is the front page, or a certain subsection.

As far as I see the default behavior is just to have one HTML file:

http://pypi.python.org/pypi/collective.xdv#usage

What would be the best strategy to use multiple theme files, slight rule variations and collective.xdv?

Plone 4.1b.

3

There are 3 answers

2
Christoph Böhner On BEST ANSWER

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>
0
JC Brand On

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.

0
Rigel Di Scala On

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.