Skip to main content

How can a rotating banner image be done in Plone?

The first step is to create a Python script that will serve up the image you want. This article assumes that you want a random image from a folder to be chosen. Python-savvy readers can use more advanced techniques, such as making a list of images to load in the same order, etc.

In the /plone_skins/custom folder, add a Script (Python) object. Put this code into it:

_from random import choice

  1. Import a standard function, and get the HTML request and response objects.
    from Products.PythonScripts.standard import html_quote
    request = container.REQUEST
    RESPONSE = request.RESPONSE
    RESPONSE.setHeader(‘Content-Type’,‘image/jpeg’)
  1. Get list of images in random_images folder
  2. images = context.images.random_images.objectValues([‘Image’])
    images = context.random_images.objectValues([‘ATImage’])
  1. Return a random choice of one of the images
    return choice(images).data_