Change the look and feel of a folder and its subfolders

by Marc Mengel last modified Dec 30, 2008 03:02 PM
If you want a subfolder to have a different appearance than the rest of your site, you can add a simple page template and a stylesheet to a folder that affects it and all of its subfolders.

It is actually fairly easy to add a stylesheet and/or extra page content by overriding the main_template. We build a new main_template in a folder which simply calls the main_template for our parent folder, and passes in a few paramter blocks,

We do this by finding the folder in the ZMI, and adding a Page Template named main_template.

This main_template should look like:

  <metal:page define-macro="master">
    <metal:block use-macro="container/[path_to_parent]/main_template/macros/master">
      <metal:block metal:fill-slot="top_slot">
        <metal:block metal:define-slot="top_slot" />
      </metal:block>
      <div metal:fill-slot="css_slot">
        <style type="text/css" media="screen"
        tal:content="string: @import url($portal_url/[path_to_stylesheet];">
        </style>
        <metal:block metal:define-slot="css_slot" />
      </div>
      <div metal:fill-slot="main">
        [before content]
        <metal:bodytext metal:define-slot="main" tal:content="nothing">
          Page body text
        </metal:bodytext>
        [after content]
      </div>
    </metal:block>
  </metal:page>

There are four strings in this template in square brackets that you would want to fill in:

  1. [path_to_parent] is the path to this folder from the Plone site folder. (you might think you can use here/aq_inner/aq_parent, but that makes a loop when this template is used in subfolders...)
  2. In the css_slot section, the [path_to_stylesheet] is the path to where you have the special stylesheet for this folder.
  3. in the main slot, you can add [before content] which will be just before the content of every page's content (but with the stylesheet can of course be placed wherever you want on the page)
  4. at the bottom of the main slot, you can similarly add something to the page.

This works by intercepting requests for the main_template made by pages in this part of the containment hierarchy, and calling the main_template in force further down, with various parameters passed -- namely the main, css_slot, and top_slot parameters.

Note that, as coded, this allows the same trick to be applied in a subfolder of this one -- both added style sheets will appear in those areas.