7. Creating initial content for the themeΒΆ

Our theme relies on some initial content structure, specifically the slider-images folder with some images inside. Let’s improve our theme package to create this content on install.

To do that we create the slider-images folder in our setuphandlers.py and load also some example images into that folder.

We have the needed images inside theme/img folder. To create the folder and the immages put the following code in your setuphandlers.py.

# -*- coding: utf-8 -*-

from plone import api
from Products.CMFPlone.interfaces import INonInstallable
from zope.interface import implementer
import os

class HiddenProfiles(object):

    def getNonInstallableProfiles(self):
        """Hide uninstall profile from site-creation and quickinstaller"""
        return [

def post_install(context):
    """Post install script"""
    portal = api.portal.get()

def _create_content(portal):
    if not portal.get('slider-images', False):
        slider = api.content.create(
        for slider_number in range(1, 4):
            slider_name = u'slider-{0}'.format(str(slider_number))
            slider_image = api.content.create(
            slider_image.image = _load_image(slider_number)
        # NOTE: if your plone site is not a vanilla plone
        # you can have different workflows on folders and images
        # or different transitions names so this could fail
        # and you'll need to publish the images as well
        # or do that manually TTW.
        api.content.transition(obj=slider, transition='publish')

def _load_image(slider):
    from plone.namedfile.file import NamedBlobImage
    filename = os.path.join(os.path.dirname(__file__), 'theme', 'img',
    return NamedBlobImage(
        data=open(filename, 'r').read(),

def uninstall(context):
    """Uninstall script"""


After adding this code to the setuphandlers.py, we need to restart Plone and uninstall/install our theme package.