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 plone.app.theming.utils import getAvailableThemes
from plone.app.theming.utils import applyTheme
availableThemes = getAvailableThemes()
for item in availableThemes:
    if item.__name__ == 'barceloneta':
        applyTheme(item)
        return

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"?>
<theme>
  <name>my-theme</name>
  <enabled>true</enabled>
</theme>
<!-- configure.zcml in my.themepackage-->  
<plone:static
  directory="theme"
  type="theme"
  name="my-theme" />
# buildout.cfg
[plonesite]
recipe = collective.recipe.plonesite
profiles-initial =
    Products.CMFPlone:plone
    Products.CMFPlone:dependencies
    plone.app.contenttypes:default
    plone.app.contenttypes:plone-content
profiles =
    my.themepackage:default

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'?>
<theme>
    <name>barceloneta</name>
    <enabled>true</enabled>
</theme>

Take care!

1 Like