Random Picture

This article explains how showing a random image on a page as you see it on  http://www.paroisse.ch.

The idea is to store images in a dedicated directory, e.g., fileadmin/images/random, and to use the extension  RandomImage to randomly choose one picture to be displayed.

Let’s start with the extension’s install/configuration process. After installing it the same way any other extension, add the extension RandomImage to your Template (Web > Template > Edit whole template record > Include static from extension).

I suppose that the website is using TemplaVoilà! and that a placeholder for the picture has been defined as being of type TypoScriptPath and whose value is lib.randomImage.

Now we just have to add the configuration to our templateTS:

includeLibs.tx_ccrandomimage = EXT:cc_random_image/pi1/class.tx_ccrandomimage_pi1.php
lib.randomImage = USER_INT
lib.randomImage {
	userFunc = tx_ccrandomimage_pi1->main
	path = fileadmin/images/random/
	fileExt = jpg,jpeg,gif,png
	renderObj = IMAGE
	renderObj {
		file = ###FILE_1###
		width = 379
		height = 179

If you don’t need to constraint the picture’s dimensions, you may simply omit parameters width and height in the configuration above.