Activating a theme programmatically

I'm using the handy-dandy collective.recipe.plonesite to automatically set up an initial Plone site object with its profiles directive pointing to my add-on and things seem just fine.

Except the Barceloneta theme isn't activated.

"Ah ha!" I thought to myself. "I'll just activate it in my add-on's setuphandlers." Voilà:

from import getAvailableThemes
from import applyTheme
availableThemes = getAvailableThemes()
for item in availableThemes:
    if item.__name__ == 'barceloneta':

Except it doesn't work. When I start my site, it still looks plain. (Although oddly, if I go to the theming control panel, Barceloneta is listed as activated!!?!)

Any ideas what I'm doing wrong? Is there a better way (i.e., one that works)?

This should work:

<!--theme.xml in profiles/default in my.themepackage -->
<?xml version="1.0" encoding="UTF-8"?>
<!-- configure.zcml in my.themepackage-->  
  name="my-theme" />
# buildout.cfg
recipe = collective.recipe.plonesite
profiles-initial =
profiles =

Thanks Jan. Following your lead, this was all I needed; a single theme.xml file and no code:

<?xml version='1.0' encoding='UTF-8'?>

Take care!

1 Like