Updating the css file

8 posts by 2 authors in: Forums > CMS Builder
Last Post: November 7, 2016   (RSS)

By paulmac - October 21, 2016

Hi

I have a background image that is defined in the css file. After I upload an image in CMSB what code do I use to update the css file?

Thanks

By Damon - October 24, 2016

Hi,

To update a css file with CMS Builder, here are the basic steps:

1. Rename .css file extension to .php so you can run PHP code.
example: style.css to style.php

2. Run the Admin > Code Generator to get the code need to publish content in the style.php page.

3. Add code to output one upload image URL if an image has been upload or else if not image, display default image:

<?php foreach ($site_settingsRecord['background_image'] as $index => $upload): ?>
 body {
 background-image: url("<?php echo htmlencode($upload['urlPath']) ?>");
 }
 <?php break; // only show one uploaded image ?>
<?php endforeach; ?>

<?php if(!$site_settingsRecord['background_image']) : //if no images have been uploaded, display default image ?>
 body {
 background-image: url("background.jpg");
 }
<?php endif; ?>

That should be it.

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By paulmac - October 25, 2016

Hi Damon

How do I link to this new file style.php

The original link to the css is <link rel="stylesheet" href="css/style.css">
What should it be now?

Thanks

By Damon - October 25, 2016

Hi,

Change this:

<link rel="stylesheet" href="css/style.css">

to this:

<link rel="stylesheet" href="css/style.php">

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By paulmac - October 25, 2016

Hi Damon

Did all that, but when I copy the files over to the server all styles are lost. So the page display completely wrong.

Paul

By Damon - October 25, 2016

I missed this part. Add this code to the very top of your style.php file:

<?php header("Content-type: text/css; charset: UTF-8"); ?>

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By paulmac - November 7, 2016

Hi Damon

I have it almost working now. However the background image isn't changing it only ever shows the image of the first record.

I am using the following code in my css

// load record from 'guided_tours'
  list($guided_toursRecords, $guided_toursMetaData) = getRecords(array(
    'tableName'   => 'guided_tours',
    'where'       => whereRecordNumberInUrl(1),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $guided_toursRecord = @$guided_toursRecords[0]; // get first record

--------

<?php foreach ($guided_toursRecord['images'] as $index => $upload): ?>
url("<?php echo htmlencode($upload['urlPath']) ?>")
<?php endforeach; ?>

--------------

I have tried a few variations of this but I cannot get it to change the image. Can you see what my problem might be?Thanks