Forum Moderators: open

Message Too Old, No Replies

@import and ampersand - can I use "&" to pass many variables?

I am passing PHP variables to a css file and the ampersand doesn't validate

         

alexis

9:47 am on Feb 18, 2005 (gmt 0)

10+ Year Member



The following code:

<style type="text/css">
@import "mycss.css?lang=en&jazz=true";
</style>

works great but does not validate. The validator suggests to replace the ampersand with its html entity (&amp;) but when I do, only the lang variable gets passed.

The way around I am using is to replace the ampersand by a vertical bar then explode the string to retrive the variables.

Is the validator lying? Do I really need to do that? is there another way to encode an ampersand other than html entity and %26 (which does the same thing as the html entity, only the first variable is passed)

tedster

6:06 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, the validator is not lying - that IS the spec.

My first thought is to wonder how many different versions of a css file you need? Is it really so many that a dynamic approach is mandatory? And if that is the case, could you dynamially cascade a few extra but small css files in, each with the specific required changes? You could build the css cascade dynamically but avoid using 2-variable query strings to do it.

And second, if you have a tested and functional page that doesn't validate, but you know why and you choose that exception intentionally - it's just not the end of the world.

zollerwagner

8:38 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



(The Tedster maybe have been saying this, but I wasn't sure, so I'll say it.)

If your need is for a different style sheet in different situations, couldn't you create differently named style sheets and then have PHP (or whatever language you're using) determine which is needed and then write a different file name into the HTML? That way, the import element wouldn't need any? or &.

g1smd

7:28 pm on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There is more than one syntax for @import; I use:

<style type="text/css">
@import url(style.css);
</style>

and I have seen also:

<style type="text/css">
@import url("style.css");
</style>

Notice the letters url in there.

Try those and see what you get.