21282 Posts in 5730 Topics by 2601 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 804 Views |
-
Different Background

24 December 2010 at 12:05pm
hello
is there a possibility to get a different background on each page?
page1 = background_image01.jpg
page2 = background_image02.jpg
page3 = background_image03.jpg
..thank you
-
Re: Different Background

24 December 2010 at 10:01pm
If the pages are different types then...
within the template (*.ss)
<% Classname = PageTypeOne %> background_image01.jpg <% end_if %>
<% Classname = PageTypeTwo %> background_image02.jpg <% end_if %>or by the URLSegment...
<% URLSegment= pageone %> background_image01.jpg <% end_if %>
<% URLSegment= pagetwo %> background_image02.jpg <% end_if %> -
Re: Different Background

28 December 2010 at 7:03am
Or try something like this to add a bgimage to each page:
<?php
class Page extends SiteTree {
static $has_one = array(
'BackgroundImage' => 'Image'
);
function getCMSFields(){
$fields = parent::getCMSFIelds();
$bgImage= new FileIFrameField("BackgroundImage", "BackgroundImage");
$bgImage->setFolderName('backgrounds');
$fields->addFieldToTab("Root.Content.BackgroundImage", $bgImage);
return $fields;
}
}class Page_Controller extends ContentController {
public function init() {
parent::init();
if($this->BackgroundImage()){
Requirements::insertHeadTags('<style type="text/css">html{ background: url('.$this->BackgroundImage()->FileName.') no-repeat 50% 0;}</style>'
);
}
}
} -
Re: Different Background

29 December 2010 at 8:46pm
if would recommend @Martijn's solution,
but if you want some random background image for any page without checking the page type I'd rather go with a decorator to the SiteConfig.php
eg
<?php
class BackgroundDecorator extends DataObjectDecorator{
public function extraStatics(){
return array(
"Images" => "BackgroundDecorator_Image"
);
}public function updateCMSFields($fields){
$fields->addFieldToTab("Root.Backgrounds", new TableField($this, "Images", "BackgroundDecorator_Image", array("Title" => "Title")));
}public function getRandomImage($fields){
return DataObject::get_one("BackgroundDecorator_Image", "SiteConfig = {$this->owner->ID}", false, "RAND()");
}}
class BackgroundDecorator_Image extends DataObject{
static $db = array(
"Title" => "Varchar"
);static $has_one = array(
"Image" => "Image",
"SiteConfig" => "SiteConfig"
);}
so you will be able to use $SiteConfig.getRandomImage.Image from your templates.
| 804 Views | ||
|
Page:
1
|
Go to Top |




