Image links not working in Stylesheet

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
User avatar
thomahawk
Power Poster
Power Poster
Posts: 312
Joined: Fri Jul 25, 2008 10:13 am

Image links not working in Stylesheet

Post by thomahawk »

Dear forum members

I just installed a fresh CMSMS and have a strange problem creating the general template: The images used in stylesheet (mostly div background images) do not work.

I checked the links, for example "images/button.png", they do work when I call them directly as an URL path, or when I put the same CSS directly into the template page (using the {literal} tag). The stylesheets as such do also work (fonts and colors etc. are displayed correctly). Only the images do not appear.

I used the latest stable release, 1.9.4.1 "Faanui"

It seems as if the stylesheet uses an other path to the directory, but I have done several CMSMS sites and never got this problem... I have no clue what else to do, any suggestions?

Thanks,
Thom
Last edited by thomahawk on Sat Mar 26, 2011 1:16 pm, edited 1 time in total.
User avatar
thomahawk
Power Poster
Power Poster
Posts: 312
Joined: Fri Jul 25, 2008 10:13 am

Re: Image links not working in Stylesheet

Post by thomahawk »

By the way, also using the complete url to the image in the stylesheet does work, f.e. http://www.homepage.com/images/button.png, but images/button.png does not.
User avatar
M@rtijn
Power Poster
Power Poster
Posts: 706
Joined: Sat Nov 14, 2009 4:54 pm

Re: Image links not working in Stylesheet

Post by M@rtijn »

You kind of already answered yourself ;)

When using 'images/button.png' the server doesn't know to what path that relates. Using a full url, solves it.

Another way, the proper CMSMS way, to solve it:
Use {cms_stylesheet} in your page template & add [[root_url]] before your links in the css files.

Like this:

Code: Select all

background: url([[root_url]]/uploads/images/something.jpg);
Make your community a better place!
User avatar
thomahawk
Power Poster
Power Poster
Posts: 312
Joined: Fri Jul 25, 2008 10:13 am

Re: Image links not working in Stylesheet

Post by thomahawk »

Thanks for your message, Martijn

I will try your solution.
However, why is this necessary now? I have done so many CMSMS sites before, and it always worked by just placing the usual internal link into the stylesheet. I just checked again and it is true, I used for example

body {
background-color: #252525;
background-image:url(images/background.jpg);

No alteration was necessary in CMS Made Simple 1.6.7 "Teremba Bay".

Thomas
uniqu3

Re: Image links not working in Stylesheet

Post by uniqu3 »

Stylesheets are bein cached in /tmp/cache folder meaning you would need to use ../../images/ or /images in case you don't like full url that is created with [[root_url]].
Before 1.8.xx stylesheets were not cached in a folder meaning path to stylesheet looked like being in root folder where path to images was correct.
User avatar
thomahawk
Power Poster
Power Poster
Posts: 312
Joined: Fri Jul 25, 2008 10:13 am

Re: Image links not working in Stylesheet

Post by thomahawk »

Thanks unique3, that explains everything. I suppose this should be mentioned in http://wiki.cmsmadesimple.org/index.php ... tylesheets
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: Image links not working in Stylesheet

Post by Wishbone »

thomahawk wrote:Thanks unique3, that explains everything. I suppose this should be mentioned in http://wiki.cmsmadesimple.org/index.php ... tylesheets
It is in the help in the backend.. Extensions -> Tags -> cms_stylesheet

Your old install was using {stylesheet}, which is relative to the root directory. The cms_stylesheets are served up from somewhere in /tmp. If you go back to {stylesheet} your old stylesheets will work.
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm

Re: Image links not working in Stylesheet

Post by RonnyK »

Correct,

there are 2 methods of calling stylesheets {stylesheet} which does all relative by default, or the newer {cms_stylesheet} which works cache-based, and thus needs the full path. As the stylesheet is cached in another folder. To make the full path appear, use the [[root_url]]/ in front of the relative images and they will appear.

Ronny
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Image links not working in Stylesheet

Post by Dr.CSS »

@thomahawk

I would also suggest you move your them images into a sub-directory in uploads/ I would never put anything in root/images, as it is only supposed to be used for cmsms itself...
Post Reply

Return to “CMSMS Core”