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

Adding variables to CSS

Go to End

2 Posts   1206 Views


Community Member, 10 Posts

21 June 2011 at 3:26am

Hey guys,

I'm at a stumbling point in my knowledge of Silverstripe and was wondering if I could ask for your suggestions.

My issue is I would like to have a user-selected background image, which is applied in the CSS, from whichever picture is selected or uploaded by an uploadify imageuploadfield.

I've done a similar slideshow, where the image is applied using the inline style attribute, although it would be ideal to have the background image path printed out to an external CSS file for each different page (probably using a page ID on the body element).

If you have tried something like this before and think you could help direct me to the most efficient method, please do!

Thanks for your responses in advance,


(aka Justify)


Forum Moderator, 1899 Posts

22 June 2011 at 1:38am


I would do this within PHP (as it's easiest to access the File/Image) and then place it into the CSS in Page init using...

public function init() {
	//get the image name into $strImage
	Requirements::customCSS("<<DO CSS STUFF HERE WITH>> $strImage");