Content rules

published Oct 11, 2007, last modified Jan 30, 2008

Plone conference 2007, Naples. Speaker: Kamon Aveya Company: Ingeniweb

Plone conference 2007, Naples. Speaker: Kamon Aveya Company: Ingeniweb

In Plone Content is king. Content is a first class citizen. You manage content. But we still do a lot of stuff manually: content modification, reviewing, publishing, awareness of content/workflow changes, collaboration, etc. Of course you can add python code to do some things automatically.

"Content rules" to the rescue! This is a new feature in Plone 3. It allows the Manager of the site to automatically do things with content.

We have a content rules engine. Rules allow automatic actions based on triggers. Rules consist of three parts: if an event happens and if a condition is True, some action is taken.

The main events that are available to the rules engine are: an object is added to a container (folder), or removed from it, or moved to another container, an object is modified, or its workflow state has changed.

Possible use cases:

  • Moving contents automatically.
  • Log content modifications in the event log or somewhere else.
  • Provide notifications as a status message.
  • Send email messages.

You get these use cases out of the box with Plone 3. They work already. So some of the things that you were doing manually or by writing some custom code yourself are now available by default.

What you can do, is manage News items better. You can put News items anywhere. You can have a Collection for having a central folder that shows all News items. But having News items all over the site is not very nice. So you can use a content rule: when a News item is published, it is moved to a specific central folder.

In the Content rules configlet in the Plone Control Panel you add a new rule with the workflow change trigger. You select some conditions then: do this for the content type News item and only for the publish transition. And you select an action: move it to a folder of your choosing.

Now you go to the root of your site and as Manager you click the Rules Tab. At that point you can say which content rule you want to use here and in sub folders if the rule is not activated globally.

You can add an email action. That has a field where you can use things like ${title} and ${url}.

Other examples:

  • Track the removal of content. This works already.

  • Prepopulate a folder, for example a MemberFolder. You can write an action for that. The start of an implementation would be:

    class IPopulateAction(Interface):
        skeleton_folder = schema.Choice(...)
    

It is powerful and extensible. Use it when it makes sense for your use case!