Creating a custom theme
In this article, we take you through the process of creating a new theme. Rather than starting from scratch, we adapt the pop theme that ships with Magnolia CMS. The changes are limited to editing a single CSS file which controls the visual identity of the site. The purpose is to demonstrate how to create a new look and feel with minor changes.

- About themes
- Registering a theme
- Creating a style sheet
- Editing the styles
- Updating images
- Assign the theme to a site
- Theme as a module
- References
About themes
A theme's purpose is to give a site unique look and feel and provide client-side functionality such as JavaScript effects. Magnolia CMS ships with a theme called pop. It creates the black and pink look you see on the demo-project and demo-features websites.
In this exercise we will change the theme's primary colors to white and blue.
You are not limited to changing the visual appearance. The Standard Templating Kit is a framework that allows you to customize page layouts too. After you learn about themes, see what STK can do.
Themes are configured in Templating Kit > Themes.
The default pop theme has four nodes:
- cssFiles contains links to the cascading style sheets which describe the presentation semantics (look and formatting). The actual CSS files are stored in the
resourcesworkspace. Learn more about CSS in themes. - jsFiles references JavaScript responsible for client-side functionality such as teaser paging, AJAX, AdminCentral menu animations, trees, embedded video player, mouse wheel support, Google Analytics and much more. JavaScript files are also stored in the
resourcesworkspace. - imaging contains rules for image variations. See the Imaging module for more information.
- bodyClassResolver registers the class that determines the page layout variations.
Registering a theme
Registering a theme means making it available to sites. Themes are registered in Templating Kit > Themes. Since this exercise is limited to changing the CSS, you only need to configure a new CSS and inherit everything else (JavaScript, images, layout variations) from the pop theme. To learn more about the inheritance mechanism, see Extending configuration.
To register a theme:
- Go to Templating Kit > Themes:
- Add a new content node and name it
blue. - Under
blue, add a data nodeextendsand set its value to../pop. This inherits all configuration from thepoptheme. - Under
blue, add a content nodecssFilesand under it a content nodestyles. This node structure is identical to the one in thepoptheme, it overrides thepopconfiguration. - Under
styles, add data nodelinkand set its value to/resources/templating-kit/themes/blue/css/styles.css. You will create the CSS file in Creating a style sheet below.
Creating a style sheet
Customize the CSS that defines the visual identity of the site. The primary style sheet is styles.css. It defines fonts, colors, links, grid, layout and branding for all possible page templates, and references template images.
To add a new CSS file:
- Go to Templating Kit > Resources.
- Create folders
/templating-kit/themes/blue/css. - Under
css, create a new nodestylesand set its type to Processed CSS.
Editing the styles
The fonts, colors, links, grid, layout and branding of all possible variations of a web page are defined in styles.css. Any image assets are also referenced. Reliance on this single CSS file allows you to change the look and feel of a site without touching the templates themselves. The images used by the pop theme are also stored in the resources workspace.
It is not strictly necessary to store this or any CSS file in the resources workspace. You can point to any valid internal or external URL. However, storing the file in the repository makes deployment and dependency management easier.
To edit styles:
- Select the
styles.csssheet and and click Edit Item. - Copy the Blue Theme style from our SVN repository and paste it into the sheet.
- Save.
div.date element.

The style definition for the div.date element looks like this. Notice the background and border colors.
div.date {
position: absolute;
top: 0;
left: 0;
margin: 0 5px 0 0;
background: #d5edfe;
border: 1px solid #abdbfe;
width: 4em;
}
Updating images
Images referenced by the pop theme in styles.css are also stored in Resources /templating-kit/themes/pop/img.
- Create folders
/templating-kit/themes/blue/img/bgsand/templating-kit/themes/blue/img/icons. - Download Blue Theme images from SVN and upload them into the folders.
- Create a new item of resource type
binary. - Click Edit Item.
- Upload the image.
- Save.
Images are referenced with a relative URL and can have the same file names as the pop theme images. Magnolia CMS handles mapping the URLs. For example:
#extras .toc-box .toc-box-section {
background: #f2f2f2 url(../img/bgs/text-box-220.png)
}
Assign the theme to a site
A theme is assigned to a site in a site definition. This is the only part where procedures between the Enterprise and Community editions differ. The Enterprise Edition supports multiple sites, each with an individual theme, whereas the Community Edition only supports a single theme. Here you assign the blue theme to a site.
Enterprise Edition:
- Go to Templating Kit > Site Definition >
/default/theme. - Set the value of the
nameproperty toblue.
- Go to Templating Kit > Site Configuration >
/theme. - Set the value of the
nameproperty toblue.
Theme as a module
It is recommended that you create a dedicated module for your own theme. This way you can decouple presentation logic from content and functionality. You only need to touch the theme module when the theme actually changes. This simplifies the deployment cycle too as you only need to deploy the theme if it changes.
To create a theme module, copy the structure of module-theme-pop and follow the Module Quickstart article on the Magnolia wiki.
The module descriptor in META-INF/magnolia/theme-<themeName>.xml defines a version handler. A theme module should use or extend the ThemeVersionHandler class. Theme modules also have a themeName property in the module descriptor.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE module SYSTEM "module.dtd"> <module> <name>theme-pop</name> <displayName>Magnolia Pop Theme Module</displayName> <description></description> <versionHandler>info.magnolia.themes.pop.setup.PopThemeVersionHandler </versionHandler> <version>1.4.2</version> <properties> <property> <name>themeName</name> <value>pop</value> </property> </properties>
ThemeInstallTask is the task that installs CSS, JavaScript and images from the module JAR into the resources workspace.
Theme specific configuration is bootstrapped into the config workspace. It is important to use the following location and filename within your module JAR for the bootstrap file: /mgnl-bootstrap/theme-<themeName>/config.modules.standard-templating-kit.config.themes.<themeName>.xml. Note especially the theme- prefix in the folder name.