Over-riding a Page Template in a Skin

by Andy Ferguson last modified Mar 17, 2010 10:08 AM
How-to override a product's page template in your own skin making sure it is applied before the original template

A quick tip that I should have remembered till the good folks on IRC reminded me...

Lets suppose you have developed your own skin for your Plone site. Its been working fine ever since the site went live. 

You want to add a new content-type; a standard product downloaded from here. Its perfect for your site - if only the gadget rendered in the foot of the main view were at the top instead.

When you look at the new product on the file system, you see the main view is rendered by an ordinary Page Template stored in the typical skin folder of a non-Zope 3 style product (i.e. not in a folder containing zcml files); perhaps called skins/productname/templates/view.pt or something similar. All you want to do is cut and paste one line of this template from the bottom to the top and you are in business.

So you do the necessary:

  1. copy the template into an equivalent location in your own site skin
  2. edit the template to suit
  3. and update your test site with the revised skin

But when you create a new object the gadget you were trying to move up the page view remains stubbornly at the bottom i.e. your revised template has not been recognized.

You experiment by browsing through your site's portal_skins folder in the ZMI and customize the original template through the web. Your change works fine that way, why does it not work in your skin?

Quite possibly, your skin is set with a lower precedence than the new product you installed. The template you changed is therefore not being found before the original. Very easy to correct:

  1. enter the ZMI and navigate to your site's portal_skins folder
  2. choose the folder's properties tab
  3. check the layers list for your (active) skin and make sure your skin has a higher precedence than the product you are trying to over-ride i.e. it should be nearer to the top
  4. if the order is wrong, just cut and paste the reference to your skin to a more appropriate location

That should be it.

Example:

  1. You install RichDocument but want to over-ride its main view template
  2. You find the template is stored in RichDocument/skins/richdocument as richdocument_view.pt
  3. Copy this template into an appropriate location in the skins folder of your skin product and edit it as required
  4. When you update your skin, the revised template is not activated and when you look in the site's portal_skins Properties you see:
    before
  5. Cut and paste the references to your skin (especially the one containing the revised template) so it appears higher in the list - above richdocument - like so:
    after
  6. Your revised template should be used in preference to the original in the RichDocument product since your skin now has a higher precedence.