Direkt zum Inhalt | Direkt zur Navigation

Benutzerspezifische Werkzeuge
Anmelden

How to get a different look for some pages of a plone-site

erstellt von pb — zuletzt verändert: 18.02.2011 15:52
It's pretty easy to attach a special look to whole sections. Styling only some pages is a different story.

I'm currently working on a site where the customer wanted some pages to look differently than others.

(I should really not do the "Hey you could also do this and that" when my time is limited!)

The pages should have a additional css and a line of text above the heading. I wanted it to look like this:

Here "what if foo..." is the Name of the folder that contains the document "...hits the bar?", being the h1.

Since the old trick with body.section-foo only works for whole sections and I needed the additional text (what if foo...) anyway I decided to go with the beloved marker interfaces.

Here is how it works:

1. Add a marker interface

In your theme-product edit your browser/interfaces.py and add:

class IMySpecialStyle(Interface): 
    """Marker Interface for  Documents with a special style
    """

 

2. Register a viewlet pinned to the Interface

In your browser/configure.zcml add:

<browser:viewlet 
   name="myspecialstyle.viewlet " 
   manager="plone.app.layout.viewlets.interfaces.IAboveContentTitle" 
   template="templates/myspecialstyle_viewlet.pt" 
   layer=".interfaces.IThemeSpecific" 
   for=".interfaces.IMySpecialStyle" 
   permission="zope2.View" 
   /> 

<browser:resource 
   name="myspecialstyle.css" 
   file="resources/myspecialstyle.css" 
   /> 

The line for=".interfaces.MySpecialStyle" activates the viewlet only for content which have the marker-interface. The viewlet-manager IAboveContentTitle inserts the viewlet just before the h1-tag of the targeted document.

 

3. Add content and styles

Now add a file browser/templates/myspecialstyle_viewlet.pt containing:

<link href="myspecialstyle.css" rel="stylesheet" type="text/css" 
      tal:attributes="href string:${context/portal_url}/++resource++myspecialstyle.css"/>

<div id="myspecialstyle-viewlet">
   <h2 class="myspecialstyle-header" 
       tal:content="python: context.getParentNode().title">
          what if foo ...
   </h2>
</div>

Instead of "getParentNode.title" I could also enter the expected line of text by hand. But like this I can reuse it for other folders.

Keep in mind that for default-pages you might want the 'grandparent‘, so you could use this

tal:define="is_default_page context/@@plone_context_state/is_default_page"

to check if it's a default page, and

tal:condition="is_default_page"
tal:content="python context.getParentNode().getParentNode().title"

to get the grandparents title.

Now create browser/resources/myspecialstyle.css and add:

#myspecialstyle-viewlet {
	position: absolute;
}

.myspecialstyle-header {
	bottom:1.45em;
	font-family: "Arial Black";
	font-size: 500%;
	font-weight: bold;
	left:-22px;
	color: #e1e1e1 !important;
	position:relative;
	z-index: 0;
}

h1.documentFirstHeading {
	z-index: 1;
	position: relative;
	padding-top: 10px;
}

 

4. Use it

Restart Zope. In ZMI go to the page in question (or rather add /manage_interfaces to it's url), select IMySpecialStyle from the available Marker Interfaces and add it.

If you remove everything from the viewlet except for the <link ...>-stuff you get a really simple way to style some selected pages.

 

 

abgelegt unter:
MarCoch
MarCoch sagt
19.01.2012 14:04
Serwis przedstawia bezplatne obrazy i filmy z branzy <a href=http://www.anonse-mazowieckie.pl>sex anonse warszawa</a>. Galerie erotyczne przeznaczone wylacznie dla widzow doroslych. Codzienna aktualizacja tresci. Zobacz teraz!
EmottossyQuon
EmottossyQuon sagt
28.01.2012 12:29
Come to see us contemporary to buy more facts and facts at all events By us at the moment to obtain more knowledge and facts regarding <a href=http://www.ulotki-online.com.pl>Ulotki</a>
Nedaphafepe
Nedaphafepe sagt
01.02.2012 11:57
Hi! my rank is Jully. I would like to meemeet seemly brat :)
This is my homepage - http://jskdh5jkd7djh4.com/l
pletcherewd
pletcherewd sagt
04.02.2012 12:33
Nike has ages again released another peachy http://www.nikeairmaxrequins.com - nike tn boring light-skinned / obsidian / orange color shoes. Caucasian canvas shoes and leather color as a panacea pro the cover unnoticeable, fender, buffet take into custody and ankle to obsidian leather with the plan for, LIKE MAX Nike logo and in the undecided to be decorated in orange. http://www.nikeairmaxrequins.com - nike tn pas cher retro look is greatest picture of open-air deem that this support is junior to the aegis adjacent nationwide, like a doxy to look at. http://www.nikeairmaxrequins.com - tn pas cher with the agreed characteristics of the times, a ditty and just literal representation, impetuous dupe layout, features uppers, soles register above cream, 270-degree apparent cad Max Associated with, the year is a turning-point in the configuration, at plain gleam barrel Barkley http://www.nikeairmaxrequins.com - nike tn requin CB34 taste.
Kommentieren

Sie können einen Kommentar abgeben, indem Sie das untenstehende Formular ausfüllen. Nur Text. Web- und E-Mailadressen werden in anklickbare Links umgewandelt.