Change background image from page?
Change background image from page?
Is there some way I can change the background image of a page directly from the page itself by means of some scripting? For the moment I use several sets of complete alike templates except for the background image, but it is a big hassle to make changes to the layout as I have to change the same thing in each and every template...
Re: Change background image from page?
You can employ a similar technique to http://www.cmsimple-xh.org/wiki/doku.ph ... der_images. For instance, modify template.htm:Korvell wrote:Korvell wrote:Is there some way I can change the background image of a page directly from the page itself by means of some scripting?
Code: Select all
<?php $backgroundimage = 'some/default/image.ext'?>
<body style="background-image: <?=$backgroundimage?>" <?=onload()?>>
Code: Select all
#CMSimple $backgroundimage = 'image/for/this/page.ext';#
Christoph M. Becker – Plugins for CMSimple_XH
Re: Change background image from page?
Thanks.
But shouldn't the background-image syntax in the body paragraph be like ?
Because I had to change it to that for it to work - well almost work. Problem now is that the variable doesn't get transfered from the page script. Do I recall something about #CMSimple scripting is not working from CMSimple_XH version 1.7 ?
But shouldn't the background-image syntax in the body paragraph be like
Code: Select all
url('<?=$backgroundimage?>')"
Because I had to change it to that for it to work - well almost work. Problem now is that the variable doesn't get transfered from the page script. Do I recall something about #CMSimple scripting is not working from CMSimple_XH version 1.7 ?
Re: Change background image from page?
Indeed, the url() notation required. The remaining issue is caused by the template overwriting the background image defined on the page. The template part should be more like:
Code: Select all
<?php if (!$backgroundimage) $backgroundimage = 'some/default/image.ext'?>
<body style="background-image: url('<?=$backgroundimage?>')" <?=onload()?>>
Christoph M. Becker – Plugins for CMSimple_XH
Re: Change background image from page?
I'm really sorry but it still doesn't work...
The variable from the page scripts simply doesn't transfer to the template - the variable is empty when the call is made in the template. Could it be because the background-image is set within the BODY tag?
Update: Been doing some more testing and no matter where I call the variable $backgroundimage in the template, it is empty unless I set it in the template as well... So it seems the variable is not being set by the #CMSimple script on the page...
The variable from the page scripts simply doesn't transfer to the template - the variable is empty when the call is made in the template. Could it be because the background-image is set within the BODY tag?
Update: Been doing some more testing and no matter where I call the variable $backgroundimage in the template, it is empty unless I set it in the template as well... So it seems the variable is not being set by the #CMSimple script on the page...
Re: Change background image from page?
I use the trick for a banner. But it equally works with BODY tag as well.
1. template.htm
2. stylesheet.css
3. on pages:
Maybe the variable $banner should be defined before its first call in template. But it works fine anyway. At least with v.1.6.10. Not tested with 1.7. so far.
1. template.htm
Code: Select all
<div id="header" class="banner <?php if($banner == ''){echo 'banner';}else{ echo $banner;}?>">
If no banner image is specified on a page, standard image is used.
Code: Select all
.banner{
background-image: url(images/banner/banner.jpg);
}.banner1{
background-image: url(images/banner/banner1.jpg);
}
.banner2{
background-image: url(images/banner/banner2.jpg) ;
}
.banner3{
background-image: url(images/banner/banner3.jpg) ;
}
Code: Select all
<h1>Page 1</h1>
<div>#CMSimple $banner="banner1";#</div>
<h1>Page 2</h1>
<div>#CMSimple $banner="banner2";#</div>
<h1>Page 3</h1>
<div>#CMSimple $banner="banner3";#</div>
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.
Re: Change background image from page?
Ah, that's it! Indeed, as of CMSimple_XH 1.7.0 the variable would have to be declared upfront (for instance in cmsimple/userfuncs.php), or one has to write:Tata wrote:Maybe the variable $banner should be defined before its first call in template. But it works fine anyway. At least with v.1.6.10. Not tested with 1.7. so far.
Code: Select all
#CMSimple $GLOBALS['backgroundimage'] = 'path/to/image.jpg';#
Also note that the Morepagedata plugin can also be used for such purposes.
Christoph M. Becker – Plugins for CMSimple_XH
Re: Change background image from page?
Also an Option, see Wiki "Tips and Tricks"
Example: en-Start.css... and so on.
Example: en-Start.css
Code: Select all
#body {
background: url(images/bg-01.jpg) 50% / cover no-repeat fixed #222;
}
„Bevor du den Pfeil der Wahrheit abschießt, tauche die Spitze in Honig!“ Ludwig's XH-Templates for MultiPage & OnePage
Re: Change background image from page?
Wow! I'm learning so much new today
GLOBALS did it - and Morepagedata makes it so convenient and easy for my client to understand and control.
THANK YOU all !
I better get reading and playing with all those tips
GLOBALS did it - and Morepagedata makes it so convenient and easy for my client to understand and control.
THANK YOU all !
I better get reading and playing with all those tips
Re: Change background image from page?
This should go somewhere into the Wiki: Assignment of variables in CMSimple scripting. New behaviour up from 1.7.x.cmb wrote:Ah, that's it! Indeed, as of CMSimple_XH 1.7.0 the variable would have to be declared upfront (for instance in cmsimple/userfuncs.php), or one has to write:Tata wrote:Maybe the variable $banner should be defined before its first call in template. But it works fine anyway. At least with v.1.6.10. Not tested with 1.7. so far.(Note that $GLOBALS['backgroundimage'] and $backgroundimage are basically the same variable.)Code: Select all
#CMSimple $GLOBALS['backgroundimage'] = 'path/to/image.jpg';#
Also note that the Morepagedata plugin can also be used for such purposes.