Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Accessing theme templates in the CMS? [SOLVED]

Go to End

4 Posts   1728 Views


Community Member, 607 Posts

7 March 2014 at 12:00pm

I'm extending LeftAndMain to create a custom CMS area. This is loosely based on the Settings area of the CMS.

After looking into how the Settings area is put together in code, I noticed this function that sets the theme to display tabs correctly:

     public function getResponseNegotiator() {
		$neg = parent::getResponseNegotiator();
		$controller = $this;
		$neg->setCallback('CurrentForm', function() use(&$controller) {
			return $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
		return $neg;

This gets a template located in /cms/templates/Includes/

So I duplicated this in my custom LeftAndMain child and created a duplicate template. This is not a module as it is very specific to the application and we want to keep code/templates in one area of the file system.

When I do the same as above, getTemplatesWithSuffix only returns

I have stepped through the code and found that even though my custom template is found, it is ignored because $theme is null in this subsequent function:

public static function hasTemplate($templates) {
		$manifest = SS_TemplateLoader::instance()->getManifest();

		if(Config::inst()->get('SSViewer', 'theme_enabled')) {
			$theme = Config::inst()->get('SSViewer', 'theme');
		} else {
			$theme = null;

		foreach ((array) $templates as $template) {
			if ($manifest->getCandidateTemplate($template, $theme)) return true;

		return false;

So how do I make the CMS aware of the theme? Or is a way of doing this?


Community Member, 607 Posts

7 March 2014 at 2:38pm

Edited: 07/03/2014 2:38pm

Worth adding: Theme is set in config.yml like so:

Name: mysite
After: 'framework/*','cms/*'
# YAML configuration for SilverStripe
# See
# Caution: Indentation through two spaces, not tabs
  theme: 'mytheme'

I thought the After: might have been the culprit, but even if I remove it entirely and do a dev/build, the CMS still can't get hold of it.


Community Member, 473 Posts

7 March 2014 at 3:31pm

The CMS deliberately unsets the theme, so it won't load templates from there. Put the templates in mysite/templates/ instead.


Community Member, 607 Posts

11 March 2014 at 8:37am

Thanks Simon,

I wasn't really interested in separating this one template from the rest of the codebase (for future maintenance reasons). But your suggestion did work.

In then end I was able to get the template to load from the theme directory by adding this to my LeftAndMain extended class:

public function init() {
	Config::inst()->update('SSViewer', 'theme_enabled', true);