Theme Package V: Creating Initial Content#

Our theme relies on some initial content structure, specifically the slider-images folder with some images inside.

We will improve our theme package to create this content on install.

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

We will add some images tp the theme/img folder. To create the folder and the images add the following code in your

# -*- 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"""
    # Do something at the end of the installation of this package.
    portal = api.portal.get()

def uninstall(context):
    """Uninstall script"""
    # Do something at the end of the uninstallation of this package.

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(
    return NamedBlobImage(
        data=open(filename, 'r').read(),


After adding this code to the file, we need to restart Plone and uninstall/install our theme package add-on.