Creating static text portlets in Plone 3.0

An explanation of how to use the plone.portlet.static product to easily create static html portlets.

Introduction

Plone.portlet.static is another great contribution from Martin Aspeli. It is very handy if your web editors want a portlet type they can easily drop static html content into and have a spash image,  flash video or email sign up form display on their site. I will run through how to set this up in a unified installer or buildout install of Plone, show an example of how to customise the portlets to not display a title and describe some example of its use.

Basic Setup

Install in Unified Installer build of Plone 3

As plone.portlet.static is packaged as an egg rather than a old style plone product the first step is to install easy_install:

$ wget http://peak.telecommunity.com/dist/ez_setup.py
$ sudo /opt/Plone-3.0.2/bin/python ez_setup.py -U setuptools

This will install easy_install in /opt/Plone-3.0.2/Python-2.4.4/bin

You can then install plone.portlet.static through the following steps:

1. Install the package into /opt/Plone-3.0.2/Python-2.4.4/lib/python2.4/site-packages directory:

$ sudo ./Python-2.4.4/bin/easy_install plone.portlet.static

2. Add the zcml slug in /opt/Plone-3.0.2/zeocluster/client2/etc/packages-includes folder, the file is named "plone.portlet.static-configure.zcml" and contains:

<include package="plone.portlet.static" file="configure.zcml" />

You will need to copy this file to the client1 packages-includes folder in order to make this package work in the first zeocluster client.

3. Restart the zope instance:

$  sudo /opt/Plone-3.0.2/zeocluster/bin/restartcluster.sh

4. Install the product via "Add Remove Products"

Installing in a buildout build of Plone 3

If you have a install of plone using buildout the steps to install it are quite easy.

1. Add " plone.portlet.static" to the list of eggs and to the "zcml" section in buildout.cfg

2. run ./bin/buildout

3. start the zope instance "./bin/instance fg"

4. Install the new product view "Add Remove Products" or the plone_quickinstaller. I used "Add Remove Products" within the plone site.

The next step

Adding a static portlet to your site

The process to add a static portlet now is:

1. Click on the "Manage Portlets" link at the bottom of the portlets.

2. From an "Add portlet" dropdown select "Static text portlet"

3. Enter a title for your portlet, this is required. We might well want to customise the static portlet package so that this is not required or we provide an option whether we display it or not.

4. Enter your html into the "Text" area, this will be rendered in the portlet.

5. Enter a footer if you want one (optional)

6. Enter a link that you want the footer and the header to go to (optional)

Making the portlet header optional

As our website manager wants to be able to use this portlet to display just a linked image or a flash video we needed to make the display of the portlet header optional. It is quite easy to change the static.pt and static.py file so that the header is not required. The one issue with not having the title filled in is that it is used in the manage portlets to see what the name of the individual portlets are. To get around that I created another field "portlet_title" and used that in the view "static.pt"

I have attached the new versions of static.pt and static.py

The website manager can now create a static text portlet and leave the Portlet Title blank and only have the html that was entered in the text area part being displayed:

 Static Portlet Edit

 

Here is an example of some of the portlets created using the static text portlet type. The first is the one resulting from the screen shot above. The second is an example of the use of the Spry Ajax toolkit to display content via tabs while the last is the result of javascript that displays a flash video.

Example of portlets produced with plone.portlet.static

Further information

This howto is the result of comments on the following howto: http://plone.org/documentation/how-to/editable-static-text-portlets

For more detail on easy_install, eggs and buildout see http://plone.org/documentation/tutorial/buildout/introduction

For more information of plone.portlet.static included more detailed installation guide see http://svn.zope.de/plone.org/plone/plone.portlet.static/tags/1.0b2/docs/

 

Attached files

Thanks!

Posted by Jon Stahl at Nov 19, 2007 03:47 PM
This is a great how-to, John! Thank you!

Your modification for optional title is a really sensible one; I hope you'll consider contributing it back to the trunk of plone.portlet.static.

Re: Thanks!

Posted by John Habermann at Nov 19, 2007 10:20 PM
I would be happy to contribute the modification, not sure what the best way to do that. Should I just email Martin with a diff or point him to the files attached to the howto.

cheers
John

Nice but for multiple static portlets ?

Posted by mojowork at Nov 23, 2007 09:51 AM
Thank you very much but I'd like to create different static portlets with a different id for each in order to put different styles.
My problem is that I'm new in PLone3.0 and I just can't find where to modify the static.pt code.

Thanx

Re: Nice but for multiple static portlets ?

Posted by John Habermann at Nov 23, 2007 08:57 PM
The package is installed in /opt/Plone-3.0.2/Python-2.4.4/lib/python2.4/site-packages/ so you would find static.pt at:
 /opt/Plone-3.0.2/Python-2.4.4/lib/python2.4/site-packages/plone.portlet.static-1.0b3-py2.4.egg/plone/portlet/static/static.pt

for example. If you are using buildout then the package will be installed in your eggs directory.

Instructions broke Plone

Posted by Chris Williamson at Nov 23, 2007 09:40 PM
I followed the instructions above for the unified installer, and now Plone is broken. When I go to the root Plone URL, all I get is:

<PloneSite at broken>

I can get into the ZMI. The Plone object has an icon and message in parentheses showing it's broken. When I click on it, it says:

"This object is broken because the CMFPlone product that created it is no longer installed or is installed incorrectly. Please contact the product maintainer for assistance.

"Note that the data associated with this product has not been lost, and will be accessible again if the product is reinstalled."

I've deleted plone.portlet.staic in package-includes and restarted Zope, but Plone is still broken.

Any ideas?

Fixed - I hope

Posted by Chris Williamson at Nov 25, 2007 02:17 AM
With Martin's help, I figured out that after installation of the egg, Zope could not find the path to import some Python modules.

I got Plone back after modifying the zopectl scripts to add the path to the modules:

PYTHONPATH="$SOFTWARE_HOME:/opt/Plone-3.0.3/zeocluster/lib/python:$PYTHONPATH"

(The part between "/opt" and "/python" is what I added.)

This got Plone going again.

To see the product and be able to install it, I also had to rename the zcml slug, to plone.portlet.static-configure.zcml.

One more thing

Posted by Chris Williamson at Nov 25, 2007 02:34 AM
I got an error with first client until I put the zcml slug into its packages-includes folder too.

Corrected in Howto

Posted by John Habermann at Nov 25, 2007 06:35 PM
Have added in your corrections to the howto. Sorry about the problems forgetting the "-configure.zcml" caused.

No problem

Posted by Chris Williamson at Nov 26, 2007 02:52 AM
How-to's need people to test them and find the bugs, just like software. Happy to do be able to do something to help. :-)

I wonder what caused the problems with my sys.path. Maybe you also should add information about adding that in zope.conf.

Oops

Posted by Chris Williamson at Nov 26, 2007 02:53 AM
I meant adding in zopectl.

It works but is it the right way

Posted by Winn King at Dec 04, 2007 04:16 AM
I found myself using this same hack. Could the author comment on whether this is the "proper" way to handle this situation?
Thanks.
And thanks for the how-to!

same problem

Posted by Hans Sandsdalen at Dec 18, 2007 02:46 PM
I have the same problem. I do not understand what your solution was (?). To just change PYTHONPATH, and restart plone did not help.

What do you mean by "zcml slug"? As I understood this, all I have to do is make a file in /opt/Plone-3.0.4/zeocluster/client1/etc/package-includes/ named plone.portlet.static-configure.zcml and with this content:
   <include package="plone.portlet.static" />

or:
   <include package="plone.portlet.static" file="configure.zcml" />

(does not make any difference). Copy the file to client2, also.

Same Case - Plone broken

Posted by Rodrigo Larranaga at Jun 06, 2008 03:04 PM
Hi All,

I followed step by step this how-to, and my installation of Plone.3.0.6 broke.

Also I try the PYTHONPATH bit, but it did not work.

I hope for nest How-to's the instructions were clearer and specify for which Plone versions they work.

Thanks...

Posted by Zhang Henry at Dec 25, 2007 10:06 AM
But how to modify it to support Chinese Language?
Information such as "title", "footer" in Chinese can not be make out portlet displays..:(

Problem with run?

Posted by Kosatko Petr at Apr 04, 2008 01:20 PM
I have a problem, when I run my Plone Site with debug mode, I see following error: ImportError: cannot import name StaticMessageFactory in file static.py on line 12 ....... Any idea??

Incompatible with plone3.0

Posted by Harald Friessnegger at Apr 14, 2008 07:56 AM
plone.portlet.static can't be used on a plone3 buildout, due to a versionconflict with plone.app.form::

  We already have: plone.app.form 1.0.4 but plone.portlet.static 1.1rc2 requires 'plone.app.form>=1.1dev'.

Wiggy told me on #plone that the most recent versions of plone.portlet.static (which are kupu enabled) do not work on plone3.0. Lukily `plone3.1`_ ships with static portlets included.

.. _`plone3.1`: http://plone.org/products/plone/releases/3.1

Be Careful!

Posted by Max at May 01, 2008 02:16 AM
I followed these instructions on a 3.0.4 install and had to reinstall entirely. A half-day of not-fun. Just make sure you know what you're doing, and maybe just wait until 3.1 for this functionality.