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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Cannot access SiteConfig from module template


2 Posts   403 Views


28 October 2011 at 4:28pm Community Member, 159 Posts


I've created a module which outputs a particular text file. I also have some fields that I have added to SiteConfig (which works fine and can be used from page templates).

However, I'm having trouble getting this module's template to use the SiteConfig data...

Here is my code:


// adds a rule to make work
Director::addRules(10, array(
   'myfile.txt' => 'MyTextFileDownload',

// add the extension to SiteConfig
Object::add_extension('SiteConfig', 'TextFileExtrasDecorator');


class MyTextFileDownload. extends Controller{

function index($url) {

return array();



class TextFileExtrasDecorator extends DataObjectDecorator {

function extraStatics() {
return array(
'db' => array(
'AuthorName' => 'Varchar',

public function updateCMSFields(FieldSet $fields) {
$fields->addFieldToTab("Root.ExampleTextFileDetails", new TextField("AuthorName", "Author"));


Here is my example text file.

The author is: $SiteConfig.AuthorName

This is the end of the file.

When I access this file (eg. I am able to download the file, but what I get is:

Here is my example text file.

The author is:

This is the end of the file.

Interestingly, I have no trouble accessing $SiteConfig.AuthorName from any normal page template.

Any ideas?

Thanks very much.


28 October 2011 at 5:37pm Community Member, 159 Posts

I got it to work by adding the following function to the controller... But is this the right thing to do?

   function getSiteConfig() {
      return SiteConfig::current_site_config();

I notice that in the Page_Controller there are some tests for alternate SiteConfigs - is it necessary to account for this?