Skip to content. | Skip to navigation

Sections
Personal tools
You are here: Home News & views Viewlets: barriers beyond borders

Posted Jan 12, 2009

Viewlets: barriers beyond borders

by Catherine Williams
— filed under: , ,

The Gloworm product makes it much easier for those new to Plone to identify and customize viewlets. But for Plone newbies, many barriers remain to understanding what viewlets are, why they are so useful, and how to manipulate them. Here are some of the pain points we've encountered.

Gloworm will get you on the road to understanding, but not all the way there...

Eric Steele pointed out in a recent post that the Gloworm product can help themers:

  • identify what components of a rendered page reside in a particular viewlet
  • customize any viewlet through-the-web (with some limitations: see below), and discard these customizations
  • move a viewlet around within its viewlet manager, via a nicer user interface than the one which Plone offers (@@manage-viewlets)

Eric commented that Plone newbies can find it hard to understand viewlets, and that by putting a border around a viewlet (as Gloworm does, temporarily) a newbie can find it easier to see what's in what viewlet. Both these observations are undoubtedly true.

However, simply being able to identify which bits of a page sit in which viewlets is only a first step to understanding and manipulating viewlets. Plone newbies also need to understand several other things about viewlets before being able to really manipulate them. Some of these concepts are particularly tricky for newbies to grasp (and bear in mind that many people responsible for theming sites come from graphic design and other non-programming backgrounds).

I spend a lot of time helping people to learn Plone. Here's where I see much of the viewlet-related pain arising. It would be fantastic if future versions of Plone, and Plone documentation, could help alleviate these.

Viewlet code doesn't sit alongside other template code: either in the ZMI or on the filesystem

Page templates such as document_view.pt and folder_summary_view.pt live in portal_skins in the ZMI and in CMFPlone/skins/[someFolderOrOther] on the filesystem. If I want to find a page template via the ZMI, I simply use the "Find" tab to search for it by name or by the code I know it contains.

So viewlet templates ought to live in the same places, and be found in the same way, right?

Sadly, no. Major source of confusion for newbies, and for themers used to Plone 2.5.

In the ZMI, some of the viewlet code (the viewlet templates) can by accessed via "portal_view_customizations". However, this code cannot be found via the ZMI's "Find" tab. This inconsistency (some stuff findable via the "Find" tab, other stuff not) is perplexing to our newbies.

Furthermore, the stuff in portal_view_customizations is only part of the code relating to each viewlet: you can see the template-like code, but you can't see other important stuff via the ZMI: python classes, zcml and xml, all of which you may need to alter, depending on the type of customization you need to make (see below).

On the file system, viewlet code resides in packages called eggs. Our typical newbie has never heard of eggs, and may not even have come across similar concepts before. The fact that (depending on how Plone was installed) folders containing eggs may not be visible at all via tools like the Mac's Finder doesn't help.

"Why can't I just use X in my viewlet code, when it works in my page template?"

A themer new to Plone needs to understand the concept of a Zope page template (such as document_view.pt or folder_summary_view.pt). Essentially, a template looks at where it is being called, and then decides what to display (e.g., what XHTML elements to populate, and what their contents should be), and how to display it (what CSS classes and IDs to apply).

"OK, I get that. So viewlets are like mini templates, that each deal with a section of the page, right? Look: I can see this TAL stuff in this page template, and I can also see it in this viewlet template."

Er, kind of... but not exactly.

Viewlets need associated python classes... sometimes

Very simple viewlets do not need their own python classes. For example, if you want your viewlet to display the same block of text on every page in your site, you may not need a python class: all you need is a template that can render the relevant XHTML. Here is an example:

<p>Go to <a href="http://example.com">our main website</a></p>

However, if you want a viewlet to do something reasonably sophisticated -- such as not display certain contents to anonymous viewers, or show the current time and date, or only display when called by a particular content type -- it needs a python class to tell it what to display.

The fact that a viewlet often relies on an associated python class to provide data to be displayed is something that many newbies don't appreciate. Even when the python class requirement is pointed out, it often confuses Plone newbies, because "other page templates" (i.e., those in portal_skins) don't require one. For example, in author.pt or folder_summary_view.pt, I could simply use the following condition

<tal:onlyShowToLoggedInPeople tal:condition="not:isAnon">
    Something we don't want anonymous users to see
</tal:onlyShowToLoggedInPeople>

to hide content from anonymous viewers, because "isAnon" is a variable available to all Zope page templates (it's defined in getMainGlobals.py). But if I want to use the same code in my viewlet, I have to define what "isAnon" is, using an associated python class (if I don't define "isAnon", I get an error message).

What's more, because it's my class, I don't need to use the specific term "isAnon" for the code to work. I could call my variable "anonymous" or "pancake" or "mountaineer", or anything else: I just have to make sure that the template calls "context/anonymous" or "context/pancake" or whatever. So different viewlet templates can contain different code that does the same thing, or the same code that does different things: very confusing to newbies.

You often need a filesystem theme product

Gloworm and portal_view_customizations are great... up to point. If you want to make certain minor changes to one of Plone's viewlets, you can indeed use these tools to effect the changes through-the-web, without touching the file system or python code.

But if you want to customize a Plone viewlet by getting it to display something that its default underlying python class doesn't compute for you, you need to write your own python class. Where do you put this class? Um, now you need to make something called a theme product.

Oh, and you want to make your own viewlet, to insert into the page among all the viewlets that come with Plone? Well you need a theme product for that too.

How do you make a theme product? Ah, well the best way to start is to use something like paster to make an egg for you. To get paster working on your machine you need something called ZopeSkel, which if you're on a Mac you can install with macports, but first you need to make sure you have Xcode... by which point, most newbies have developed a distinctly glazed look**.

** Many thanks to Joel Burton who has alleviated some of the "technology shock" pain for newbies, with his web-based version of paster. This can avoid many hours of frustration trying to install ZopeSkel and all its dependencies.

You mean I need to write Python code?!? Help!!!

Many Plone newbies are not just new to Plone, but new to Python and object-oriented programming... and even programming per se. Having to do apparently complicated stuff (python programming) to achieve apparently simple ends (changing some text on a page) can give some people the heebie jeebies.

What's "context"? I thought I knew, but now I'm not sure

Newbies learning to customize templates in portal_skins quickly learn that "context" means the place where the template is rendering. For example, if the document_view template is rendering a page called Financial Aid inside an Education section of our site, "context" means home/education/financial-aid. And if we want our template to display the title of the object we are on, we could write:

<h2 tal:content="context/Title">Page title here</h2>

Following this logic, it would be reasonable to assume that "context" is also the place where a viewlet renders. And, indeed, the above code does work in a viewlet template. However, when we try to call "context" inside the python class for our viewlet, we get an error to the effect that context is unknown... unless we know to call "self.context" instead of simply "context". To the python class, "self.context" is the viewlet in the context of the place it is called. Simple, yes, but not obvious to many newbies, and the cause of much gnashing of teeth.

Argh, ZCML: something else to learn (on top of TAL, METAL and Python)

Anyone putting a custom viewlet in their own theme product needs to register that viewlet using a configure.zcml file. Newbies have rarely encountered ZCML before. It's yet another thing to learn to deal with. It can take a while to appreciate that:

  • the viewlet registration must either point directly to a template (if a python class is not required), or to a python class that itself points to a template... you shouldn't specify both a class and a template
  • this is where you need to specify what viewlet manager should handle a custom viewlet
  • the viewlet's manager must be specified by interface, not by name (and newbies often don't understand what interfaces are)
  • A layer needs to be specified, so that the viewlet only appears when it should (again, newbies often don't understand layers, or how these relate to the "layers" of portal_skins)

In our experience, newbies typically regard ZCML as black magic.

Viewlets.xml and Generic Setup: yet more (gibber, drool)

If you want to do any of the following...

  • Move one of Plone's default viewlets between viewlet managers
  • Use a customized version of one of Plone's viewlets, and that customized version is sitting in a filesystem theme product
  • Add your own viewlet in among Plone's viewlets

...you will need to specify these changes using a viewlets.xml file in your theme product's install profile (typically in profiles/default). In this file, you can:

  • Hide one or more of Plone's default viewlets
  • Specify where you want your custom viewlets to appear, in relation to the other viewlets in a particular viewlet manager

Oh, and by the way, if you have made certain changes and you want your theme product to uninstall cleanly, you will also need an uninstall profile containing another viewlets.xml.

Easy when you know it, but yet more complexity for our poor newbies.

In summary

New themers often want to make what they regard as minor customizations to an out-of-the box Plone 3 site. For example, they want to move the site actions to the footer, or make certain parts of the footer be invisible to anonymous viewers. So they can be flabbergasted to find that, in order to effect these "minor" changes, they need to make a filesystem theme product in which they need to change between two and five separate files (a template file, a python class, a zcml file and one or two viewlets.xml files), each of which requires a different "language" to modify (TAL, Python, ZCML and XML, respectively). They also need to understand how to select what they should do out of a range of possible things they could do (do I need a python class, a viewlets.xml, an uninstall profile?)

We often hear people say "theming used to be so much easier in Plone 2". Indeed, in Plone 2, the newbie just had to cope with page templates, TAL, and perhaps small amounts of in-template python. In Plone 3, there is so much more to understand before one can be productive.

Core Plone developers might be quite surprised at the things I have highlighted. Yes, it's all pretty obvious once you understand how it works. But it's complicated, and we should anything we can do to make it easier -- whether that be better documentation, or more tools to aid through-the-web customizations, or getting rid of ZCML and generic setup, or anything else. If we don't make it easier, we risk fewer people using Plone.

 

Document Actions

Not surprised

Posted by Martin Aspeli at Jan 12, 2009 09:37 PM
Hi Catherine,

Thanks for writing this up! I'm not at all surprised by this pain, though :)

For Plone 4, we're considering some pretty radical changes to the way the page is composed and rendered, with much more power pushed into "simple" HTML or small templates that are easy to write. I hope that you won't need any XML or Python at all to do most simple operations, and only very simple Python for the ones that require a bit more power.

The fundamental problem at the moment is that we're not really using viewlets for the right things. Viewlets are great for creating pluggable UIs: I create this "space" here (a viewlet manager) where third party code can provide custom snippets to the user. We wanted to make Plone easy to extend, and so we moved lots of our UI into such pluggable spaces where they could be augmented or overridden. However, this was taking it all a step too far. Much of what's in viewlets (probably the stuff your themers want to move around) is really just part of a template, or part of a site layout.

In Plone 4, I think we'll see a model where we have a few viewlet managers for third party code to plug into, but the dynamic parts of the page are managed in a much more "flat" fashion. You'll probably get away with just dragging a few things in an HTML editor for most of your basic layout tasks. For more complete "branding" operations, we'll probably ship with Deliverance. See deliverances.openplans.org.

Martin

P.S.
Getting rid of GS would be wrong. However, you shouldn't need GS just to decide what boxes are shown on your site and which ones of the defaults to hide.

All for the birds?

Posted by juh at Jan 13, 2009 04:00 AM
So what does this mean? Is it all for the birds to learn Plone 3 theming? Shall we better do nothing and wait for Plone 4?

Sorry...

Posted by Martin Aspeli at Jan 13, 2009 09:35 AM
I'd possibly look into Deliverance for theming right now. Deliverance trunk (0.3) is quite usable now, and we're using it to theme the new Plone.org, which is a Plone 3 site. It is not a be-all and end-all for theming, since you may still need to write custom viewlets or views if you want to alter the actual data that comes out of Plone, but for wrapping a new look onto it, it'd be a useful (and almost certainly future-proof) investment.

I wouldn't just wait for Plone 4, though. It's a year off at least. We're discussing the proposed new model now. In a few weeks, we'll probably see a more concrete proposal. When that happens, I hope we'll get your input!

But the advice is always the same: focus on what you have now, rather than what could be in the future. There are no guarantees.

Martin

Simpler is great... will Deliverance really be seen as simpler, though?

Posted by Catherine Williams at Jan 13, 2009 11:20 AM
Thanks for all the great comments. One of the amazing things about the Plone community is the passion and participation of so many people, who not only think carefully about improvements to Plone but work hard to implement them. It's inspiring to be part of the debate.

So in the spirit of debate, what about the risk that making people learn about Deliverance, on top of everything else, will be for some people the final straw that breaks the back of using Plone... not because they are dumb or don't want to learn, but because learning takes time that they just don't have.

I'd argue that for Deliverance to be embraced by newbies, the learning curve in other areas needs to be seriously lessened. It sounds as if Plone 4 plans have this requirement thoroughly in mind (...but, as David Little points out in one of the comments here, changing a whole heap of things between Plone 3 and Plone 4 has its own complications...)

One further observation I'd make is that if Deliverance is now in a state where it can be used in production, we should improve the documentation for it.

Yes, Deliverance *should* be simpler

Posted by Steve McMahon at Jan 13, 2009 12:02 PM
Thanks for a great article, Catherine.

I've been watching over Alex Limi's work on retheming Plone.Org using Deliverance, and I'm convinced that it is, in fact, going to make things much easier. It's also not something folks need to wait for: it's available now.

There is definitely some serious documentation and good "best practices" thinking to be done, though. If Deliverance is used well, it will reduce the number of layers and their complexity. Used wrong, it's just another layer ...

wow

Posted by Yuri at Jan 13, 2009 05:22 AM
great post!

Martin: what about just adding viewlets as we do in portlets, with a drop down menu?

Adding viewlets

Posted by Martin Aspeli at Jan 13, 2009 09:38 AM
I don't think that's really feasible. Viewlets don't provide enough data for that to make sense, and aren't really designed to be admin-managed.

But as I said, the idea is that viewlets should really only be used by applications that want to declaratively plug themselves into a pre-defined, named region in the UI. They're not ideal as a general "page composition" mechanism, but right now we don't have anything that's better. What we're discussing is a model where you start off with a simple HTML page and then enrich it with dynamic components that are initially just referenced via a name (actually, a URI). This way, you can write simple dynamic components (we call them tiles) that feel a lot like viewlets (and it should be easy to turn existing viewlets into tiles) but which are easier to move around, introspect and register.

Martin

Roll your own public-facing skin, it's much easier!

Posted by Daniel Nouri at Jan 19, 2009 07:44 PM
A very viable alternative to working with and around the existing Plone interface is to roll your own and completely separate public-facing skin. This is quite easily achieved, and lets you forget about all the confusing ways that a Plone page is set up when designing your site.

We're using this approach in a big site, and it's working well. Our team consists of a web designer who doesn't have much knowledge about the innards of Plone. Still, he can be really productive.

We tried Deliverance, but found that still working on top of Plone's default UI and making it fit isn't what we were looking for.

Of course you lose the advantage of having the adminstration UI and the public UI look like the same thing. But there's just so many ways that you can screw up the usability of Plone's UI when mangling public UI and administration UI be the same thing.

Here's some ZCML to get you started:

  <!-- Define our browser layer for the public skin -->
  <interface
      interface=".interfaces.IPublicSkin"
      type="zope.publisher.interfaces.browser.IBrowserSkinType"
      name="PublicSkin"
      />

  <!-- Define the default view of all of Plone's content types to be "index.html" -->
  <browser:defaultView
      for="Products.CMFCore.interfaces.IContentish"
      layer=".interfaces.IPublicSkin"
      name="index.html"
      />
  <browser:defaultView
      for="Products.CMFCore.interfaces.IFolderish"
      layer=".interfaces.IPublicSkin"
      name="index.html"
      />

  <!-- Register a view for "index.html" -->
  <browser:page
      for="Products.CMFCore.interfaces.IContentish"
      layer=".interfaces.IPublicSkin"
      class=".main.Main"
      name="index.html"
      permission="zope2.View"
      />
  <browser:page
      for="Products.CMFCore.interfaces.IFolderish"
      layer=".interfaces.IPublicSkin"
      class=".main.Main"
      name="index.html"
      permission="zope2.View"
      />

Where main.Main is a simple BrowserView that's much like your "main template". Now add a rewrite like this one to make your public skin available (example from an nginx buildout configuration). The key here is that you always traverse "++skin++PublicSkin" to access your public skin:

  rewrite ^/(.*)$ /VirtualHostBase/http/${nginxctl:server_name}:${nginxctl:nginx_port}/++skin++PublicSkin/portal/VirtualHostRoot/$1 last;

Sure it's

Posted by Malthe at Jan 20, 2009 05:42 AM
very cool...

Malthe is right..

Posted by Miziodel at Jan 20, 2009 02:11 PM
really clever.. and it's been there the whole time :)

not always feasible, but still very often.

Thanks Dani!

right on!

Posted by alan runyan at Jan 20, 2009 09:55 PM
http://plone.org/documentation/tutorial/staged-site

This is the "old way" where we did something like:
request = context.REQUEST
if request.get('URL').startswith('http://public'):
    context.portal_url.getPortalObject().changeSkin('Retail View')

But I completely agree. Ditch the Plone UI for the public facing website. Stop pulling the wool over your own eyes. Just make your own simple (and thus fast) skin that pulls the attribues your page's need.

Plone's knobs are good for content authors. Any "user generated content" or non-editor is not going to be happy with Plone's "default look and feel". This is how http://www.oxfamamerica.org/ is configured. The admin interface looks like Plone. The "retail view" is what you see at the URL. The simplicit of the UI enables lots of flexibility.

Daniel - I would love to hear more about deliverance. Was it painful? Please share experiences.

Entransit/ContentMirror take "separating admin/retail" to a physical extreme. Check out http://www.protoolreviews.com/ (pylons frontend ontop of mysql and search is by SOLR). The entire frontend + plone admin was done by someone who didnt know Plone!!

decoupling the administration/editing from the consumption/delivery of content is probably the most under-discussed topics in Plone land. A lot more people could enjoy Plone if we talked about both: physically separating or simply "changing skin based on rewrite/url"..

great post
-runyaga

Where's the off switch?

Posted by Anonymous User at Jan 23, 2009 05:03 PM
Having attended Plone Bootcamp for version 3 this last summer in DC and being a Zope/Plone user for many years I found it frustrating that as Plone gets geometrically more complex there are seemingly less controls for eliminating uneeded features.

Before Plone us Zopistas hand-rolled our own CMF features on a raw Zope installation. Creating workflows, templates, skins, portlets and role-managers with python and were able to build streamlined systems which performed well and didn't confuse the maintainers. Now with P3 in all it's unweildy, bloated glory I find myself frequently hacking away with a meat cleaver to trim the fat like Daniel did above. Honestly, why can't we just simply shut things off?


 

Plone 3 theming is overly complex

Posted by David Little at Jan 13, 2009 10:03 AM
Thanks for this interesting article. I totally agree, Plone 3 theming is way too complex. I've been working with Zope/Plone for a few years and have created a few Plone 3 themes but, every time I do I have to spend ages ages with the documentation.

Most recently, I created a social bookmarking viewlet for a Plone 3 version of our old Plone 2.5 theme -- just a few lines of code for Plone 2.5.3; for Plone 3 I had to edit ZCML, Python classes, Interfaces, XML as well as the TAL. As you suggest, once you've got it, it makes sense (and it feels like a great intellectual achievement once you have got it). But, I've never understood why it needs to be quite so complicated. I'm sure it makes sense to programmers who care about the "proper" programmatic way to do things, but what about the end users who have to work with it?

It will be interesting to see how theming in Plone develops. As you suggest, the current complexity could put people off, although ironically, changing the process again could also cause its own complications -- *another* system to learn!

Viewlet screencasts

Posted by Catherine Williams at Feb 20, 2009 11:32 AM
I've made a couple of introductory screencasts on viewlets in Plone 3 to complement the documentation on plone.org, our wiki and elsewhere. Actually, it's one big screencast, but I split it into 2 to upload it to youtube (which has a 10 minute maximum duration for videos):
 * Part 1: http://weblion.psu.edu/docu[…]lets-in-plone-3-part-1-of-2
 * Part 2: http://weblion.psu.edu/docu[…]lets-in-plone-3-part-2-of-2
Need help now?

Immediate assistance is available during university work hours:

News & views…
Posted Oct 13, 2009 Portlets gone wild with ContentWellPortlets 2.0.1 This new release adds the ability to add portlets to the footer area. It also has 6 portlet managers per area. This means 20 total portlet managers including the 2 on the sides that ship with plone.
Posted Sep 17, 2009 Plone 4 – An interview with Zope News Jan Ulrich Hasecke interviews me for Zope News.
Posted Aug 31, 2009 Web Services API for Plone Alpha 3 Release Details the release of the wsapi4plone.core package and the plans for future releases. The final report of the AtomPub for Plone Google Summer of Code project.
Posted Aug 28, 2009 Content editing and creation in Plone is faster with archetypes.schematuning Some bench marks of content editing and creation in Plone with and without archetypes.schematuning installed.
More news & views…