ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Problem Linking to CSS with Path Variable

March 15, 2011 12:43pm

Subscribe [3]
  • #1 / Mar 15, 2011 12:43pm

    redpigeon

    10 posts

    Hi all:

    For some reason I’m having trouble linking to my CSS template with a path variable. 

    Everything works fine when I do this:

    <link rel=“stylesheet” href=”{stylesheet=styles/default}”>

    But as soon as I change “stylesheet” to “path” the CSS fails to load.  The template type for my template is set as “CSS”, as mentioned here: http://ellislab.com/expressionengine/user-guide/templates/globals/stylesheet.html

    My reason for wanting to do this is that I want my CSS template to use different icon sets for different users.  By using a variable {icon_path} I can load the appropriate icons right from the CSS and don’t have to manually code the CSS into the original .php template (which is what I have been doing).

    Any suggestions?  Does this have anything to do with the fact that my CSS has curly braces in it - perhaps EE is parsing them as variables?  If so, is there any kind of escape character for curly braces?  I’m already following each brace with a new line.

    Thanks in advance!

  • #2 / Mar 16, 2011 7:30am

    John Henry Donovan

    12339 posts

    Welcome to the forums redpigeon 😊

    What version and build of EE are you using?

    What does your code now look like? Is it like this?

    <link rel="stylesheet" type="text/css" media="all" href="{path=channel/channel_css}" />

    That should work for you

    Does this have anything to do with the fact that my CSS has curly braces in it - perhaps EE is parsing them as variables?

    No. Not so long as the template type is set to CSS Stylesheet

    Can you provide a link to your stylesheet?

    What happens when you put a direct link to the stylesheet in your browser?

    What tags are you using in your stylesheet?

  • #3 / Mar 16, 2011 9:50am

    redpigeon

    10 posts

    Thanks John; I appreciate the help.

    I figured out the problem - thanks to your suggestions!  When I compared the URLs generated by using the “stylesheet” method vs. the “path” method, I noticed that the “path” method was generating URL’s without the question mark in them.  So I re-enabled “Force URL query strings” and all works fine now.

    Having said that, though, I ran into the problem of not being able to retrieve the correct channel entry data from within the CSS.  Normally, I would use url_title_path=, combined with {exp:channel:entries}, but that doesn’t seem to work when calling a CSS stylesheet.  It looks like embedding will do the trick, though, because I can define the necessary variable in the embed command. 

    Do you have any suggestions for retrieving channel entry variables from within the CSS?  Or do you think am I better off just using an embed to embed the CSS into the HTML header?

    Thanks again!

  • #4 / Mar 16, 2011 5:06pm

    Sue Crocker

    26054 posts

    Is there a reason you need to use any sort of url_title_path in a css file? Can you give us an idea how you want to use this?

  • #5 / Mar 16, 2011 9:50pm

    redpigeon

    10 posts

    Thanks Sue,

    Sorry, what I meant to say was that I would like to link to the CSS using url_title_path so that I can use an {exp:channel:entries} tag pair to plug the value of a channel entry field into the CSS.

    So if my channel entry has a variable called {icon_path}, I’d like to link to the CSS using url_title_path so that I can use {icon_path} in the CSS.  Is this possible?

    Thanks for your help!

    Will

  • #6 / Mar 17, 2011 3:13pm

    Sue Crocker

    26054 posts

    If you see this page in the docs;

    http://ellislab.com/expressionengine/user-guide/templates/globals/stylesheet.html

    You’ll see that you can’t use embeds or variables like {icon_path}.

  • #7 / Jul 19, 2011 9:57am

    redpigeon

    10 posts

    Sorry, I forgot to update this one.  I ended up embedding the stylesheet instead of linking to it via a path variable or the stylesheet global variable.  Seems to do the trick. 

    Thanks John and Sue for all your help.

  • #8 / Jul 19, 2011 10:10am

    Sue Crocker

    26054 posts

    Sounds good.. If anything else comes up, please do let us know in a new thread..

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases