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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Requirements::customCSS Not working [solved] (SS 3.1.5)


Go to End


9 Posts   2552 Views

Avatar
digibrains

Community Member, 130 Posts

18 November 2014 at 5:16am

Edited: 18/11/2014 5:39am

Ah-Ha! That's it!

So, it's not a bug in the code, it's a poorly written doc with an incomplete example.

For anyone else who stumbles on this, this works:

<?php
class Page extends SiteTree {

	private static $db = array(
	);

	private static $has_one = array(
        'MyImg' => 'Image'
	);

	public function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Main', new UploadField('MyImg'), 'Content');
        return $fields;
    }

}
class Page_Controller extends ContentController {

	private static $allowed_actions = array (
	);

	public function init() {
        $MyVar = $this->MyImg()->getURL();
		parent::init();
Requirements::customCSS(<<<CSS
    .test {
        background-image: url($MyVar);
    }
CSS
);
	}

}

Thanks, everyone for your help! Much, much appreciated.

Chris

Go to Top