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.

Customising the CMS /

Adding variables to CSS


Reply


2 Posts   594 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, 1799 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");
}