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.

Customising the CMS /

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

Adding variables to CSS


Go to End


2 Posts   1613 Views

Avatar
Puppy

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,

Jimi

(aka Justify)

Avatar
swaiba

Forum Moderator, 1899 Posts

22 June 2011 at 1:38am

Hi,

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() {
	parent::init();
	//get the image name into $strImage
	Requirements::customCSS("<<DO CSS STUFF HERE WITH>> $strImage");
}