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
- 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’)
- Get list of images in random_images folder
- images = context.images.random_images.objectValues([‘Image’])
images = context.random_images.objectValues([‘ATImage’])
- Return a random choice of one of the images
return choice(images).data_