Personal tools
You are here: Home Team Alex Clark Blog Placeful Theming

Placeful Theming

— filed under:

We should do this out of the box!

Placeful Theming

Placeful... theming?

I had to do a bit of placeful theming lately and I thought I would share the techniques I used (thanks davisagli, jonbaldievieso, vedawms). Let's say you have a Plone 3 site, and for some location /foo/bar/baz, you want 'baz' and everything below it to look different. I made this change through the web because I was in a hurry, but the same can be done in filesystem code.

The steps are:

1. Override getSectionFromURL (navigate to portal_skins/plone_scripts/getSectionFromURL and customize)

Normally, this bit of code returns the section id for whatever section you are in. So if your site has three top level folders A, B, C, getSectionURL returns section-A when you are inside of A, section-B when you are inside of B, and so on. However, when you are inside of a sub-section, e.g. /A/news-items-folder, it *still* returns the section id, in this case section-A. The override makes getSectionURL return the sub-section, e.g. /A/news-items-folder, or /foo/bar/baz.

# Courtesy of jonb at onenw.org
# getSectionFromURL
contentPath = context.portal_url.getRelativeContentPath(context)
if not contentPath:
return None
else:
s = ''
sectionId = ''
for pathItem in contentPath:
sectionId += pathItem + '-'
s += 'section-' + sectionId[:-1] + ' '
return s[:-1]

2. Override plone.logo (navigate to /portal_view_customizations/zope.interface.interface-plone.logo and customize)

For some reason (good or not, I don't know) Plone includes an image tag in the html code it uses to generate the Plone logo. This means that it will always output something like:

img src="logo.jpg"

which is a problem if you want to placefully replace the logo because there is no easy way to do it (perhaps you could use some trick to return a different image file with the same file name).

Plone ships with:

<a metal:define-macro="portal_logo"
id="portal-logo"
accesskey="1"
tal:attributes="href view/navigation_root_url"
i18n:domain="plone">
<img src="logo.jpg" alt=""
tal:replace="structure view/logo_tag" /></a>

Replace that with:

<div metal:define-macro="portal_logo" id="portal-logo">
<a accesskey="1"
tal:attributes="href view/navigation_root_url"
i18n:domain="plone"></a>
</div>

3. Add CSS (Navigate to /portal_skins/plone_styles/ploneCustom.css and customize)

Next, add in some CSS to make use of the previous two changes:

body.section-foo-bar-baz {
background-image: url(gradient.png);
}

.section-foo-bar-baz #portal-globalnav li a {
border: 0px;
background: #0066CC;
color: white;
font-size: 110%;
font-face: bold;

}

.section-foo-bar-baz #portal-globalnav {
background: #0066CC;
padding: 0.25em;

}

.section-foo-bar-baz #portal-breadcrumbs,
.section-foo-bar-baz #portal-personaltools {
background: white;
}

.section-foo-bar-baz #portal-top {
background: white;
}

.section-foo-bar-baz #portal-logo {

margin: 1em;
background-image: url(ama_logo.gif);
background-repeat: no-repeat;

}

.section-foo-bar-baz #visual-portal-wrapper {
background: white;
margin: auto;
width: 883px;
position: relative;

}

.section-foo-bar-baz body {
background-image: url(gradient.png);
background-repeat: repeat;
}

#portal-logo {
margin: 1em;
background-image: url(logo.jpg);
background-repeat: no-repeat;

}

#portal-logo a {
display: block;
width: 650px;
height: 80px;
}

I hope this helps someone get started with placeful theming.

Document Actions

Great stuff!

Posted by Anonymous User at Jul 20, 2008 12:38 PM
This should be a plone.org/documentation how-to!

Very useful - thanks

Posted by Anonymous User at Jul 20, 2008 05:46 PM
The need to have a sub-section of a site look different from the overall site is a common one. So thank you for the clear explanation! +1 to the idea of adding this to the plone.org documentation.

collective.phantasy

Posted by Anonymous User at Jul 21, 2008 04:58 AM
The maintainer of FCKEditor start a product called collective.phantasy that allow you to do such a work in TTW:
http://svn.plone.org/svn/collective/collective.phantasy/

This product is really a great improvement face off CSSManager or a work in portal_skins.

collective.phantasy...

Posted by Anonymous User at Jul 21, 2008 08:27 AM
...has been started during the Paris Plone sprint 2008 by the guy who was just a couple of desks from you (Jean-Mathieu Grimaldi). I can understand you were too much concentrated on your - excellent - work on PSC with Tarek to notice this ;o)

Cheers
--
Gilles Lenfant

How does that work?

Posted by Anonymous User at Jul 25, 2008 05:05 PM
I would add this CSS works because plone_templates/main_template has this HTML snippet:
<body tal:attributes="class string:${here/getSectionFromURL} template-${template/id};
dir python:test(isRTL, 'rtl', 'ltr')">

what wasn't obvious, at least to me.

Apart from that, thanks for pointing this out to us!