Skip to content. | Skip to navigation

Personal tools
Log in
Sections
You are here: Home Web Plone Plone 3 View Customization Walkthrough

Plone 3 View Customization Walkthrough

Here's how to customize the logo template in Plone 3. It's actually quite painful.

Gather Information

click the plone.logo link in portal_view_customizations
note the name (plone.logo), the zcml file (plone.app.layout.viewlets/configure.zcml)

Check out the configure.zcml file

<!-- The logo -->
<browser:viewlet
    name="plone.logo"
    manager=".interfaces.IPortalHeader"
    class=".common.LogoViewlet"
    permission="zope2.View" 
 />

Two important things here:

1. There is no "template" attribute. This means that the name of the template is going to be hardcoded in the python class
2. This python class is defined by the "class" attribute: class=".common.LogoViewlet"

Check out the class

So I'm going to look at that class, which is in the module (file) called 'common.py'

class LogoViewlet(ViewletBase):
    index = ViewPageTemplateFile('logo.pt')

    def update(self):
        super(LogoViewlet, self).update()

        self.navigation_root_url = self.portal_state.navigation_root_url()

        portal = self.portal_state.portal()
        logoName = portal.restrictedTraverse('base_properties').logoName
        self.logo_tag = portal.restrictedTraverse(logoName).tag()

        self.portal_title = self.portal_state.portal_title()

That first line of the class is the hard-coding of the template I mentioned.  The implications of the hardcoding are that you have to override the class, which is dumb, but people weren't thinking clearly.  Here's what I do...

Create your new, improved version

Define a new logo viewlet in zcml

I actually define a *new* logo viewlet rather than overriding Plone's (which I hide), because I think this is less confusing when you come back to it in 6 months (or someone else works with it).

Here's the configure.zcml (add this inside configure.zcml in your theme product's browser folder):

    <!-- The logo -->
    <browser:viewlet
        name="myplone.logo"
        manager="plone.app.layout.viewlets.interfaces.IPortalHeader"
        class=".viewlets.MyLogoViewlet"
        permission="zope2.View" 
        />
Note that 'manager' is now the *full* path to plone's interface definition for the portal header viewlet manager, and 'class' points to a python class in your own product's viewlets.py

module.

Subclass plone's LogoViewlet class

Change only the template definition (add this to viewlets.py in your theme product's browser folder):

from plone.app.layout.viewlets.common import LogoViewlet

class MyLogoViewlet(LogoViewlet):
   index = ViewPageTemplateFile('my_logo.pt')

Customize the template

Copy logo.pt to your browser/ dir, and rename it my_logo.pt

Test

Put an error in it so you know you're hitting it (you'll fix later)

Restart zope

Should get an error from your bad template

Fix template as desired

Configure the viewlets 

Go to @@manage-viewlets.  Make sure your new viewlet is displaying in the proper place.  Move it up or down within the viewlet manager as desired.  Hide the original logo viewlet.  Note that depending on your CSS, the old and the new logo may appear right on top of one another.  For a sanity check, hide them both then show your myplone.logo viewlet.

Document Actions

Comments (0)

« February 2012 »
February
MoTuWeThFrSaSu
12345
6789101112
13141516171819
20212223242526
272829