How to create a custom skin ?

Asked by Baiju Muthukadan on 2007-07-12

What are the modules required to create a custom skin ?
Is there any example for creating custom skin ?
Can I customize Rotterdam skin ?

Question information

Language:
English Edit question
Status:
Solved
For:
Zope 3 Edit question
Assignee:
No assignee Edit question
Solved by:
Baiju Muthukadan
Solved:
2007-07-12
Last query:
2007-07-12
Last reply:
Best Baiju Muthukadan (baijum) said : #1

Skins are technically interfaces defined using zope.interface. To create a custom skin it is always better to inherit from a standard skin interface. It is by convention that skins will be created in sub-package named skin in your browser package of your main package. For example if your package name is foo, then foo.browser.skin will be the skin package, but this is not mandatory. Your skin interfaces can be defined in foo.browser.skin.interfaces. Here is an example interfaces.py:

from zope.app.rotterdam import Rotterdam

class IShanghaiSkin(Rotterdam):
  """Wo zhu zai Shanghai"""

To register this, you can use interface and utility directives in zope namespace. The type of the IShanghaiSkin? skin is zope.publisher.interfaces.browser.IBrowserSkinType?. Here is a sample configure.zcml:

<interface
    interface=".interfaces.IShanghaiSkin"
    type="zope.publisher.interfaces.browser.IBrowserSkinType"
    />

<utility
    component=".interfaces.IShanghaiSkin"
    provides="zope.publisher.interfaces.browser.IBrowserSkinType"
    name="ShanghaiSkin"
    />

As a shortcut, you can also use the interface directive and pass the new name parameter. The following one directive has the same effect as the two above regarding the skin registration:

<interface
    interface=".interfaces.IShanghaiSkin"
    type="zope.publisher.interfaces.browser.IBrowserSkinType"
    name="ShanghaiSkin"
    />

You can register views and resources on the skin directly:

<browser:resource
    name="zope3logo.gif"
    file="shanghailogo.gif"
    layer=".interfaces.IShanghaiSkin"
    />

As you can see, you need not to create an extra layer just to create a custom skin. A typical browser:page with with layer specified is like this:

<browser:page
    for="*"
    name="dialog_macros"
    permission="zope.View"
    layer=".interfaces.IShanghaiSkin"
    template="dialog_macros.pt"
    />