RE: [SMARTY] Using Smarty for Dynamic CSS
| From: | MPN | Date: | Fri, 03 May 2002 15:53:27 +0000 |
| Subject: | RE: [SMARTY] Using Smarty for Dynamic CSS | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-4034@lists.php.net to get a copy of this message | ||
Yes I agree (and so does W3C), however I prefer to use external style
sheets. :) Note, in my hastiness, I used CSS instead of HTML syntax in the
examples. Corrected below.
> Example:
>
> <p class="{$paraopt}">Blah blah</p> {* This assumes the entire
> selector is passed *}
>
> OR
>
> <p class="{#$paraopt#}">Blah blah</p> {* Where $paraopt is a
> simple identifier (a1, a2, ...) and the config file holds the
> actual CSS selector choices (news1, news2...) *}
OK, now to expand on the thought.
Lets say we store the user CSS options in a separate style sheet. This
would serve to keep the overall size of the primary style sheet down, and
gives a simple way of changing a particular values (color, size, etc..)
within a static CSS file without having to redefine the entire class/element
or define a bunch of selectors that never get used.
So basically you have a parent element that defines defaults for that HTML
element, then using classes, change particular values within that parent
element.
So in effect you have something like this in the primary style sheet:
p {
display: block;
background-color: transparent;
color: #505050;
font-family: Geneva, Verdana, Arial, sans-serif;
font-style: normal;
font-weight: normal;
font-size: 9pt;
text-align: left;
}
And something like this in the user options style sheet.
p.news1 {
color: red;
font-variant: small-caps;
text-decoration: underline;
}
Then you conditionally import the users style sheet into the primary style
sheet. If the inheritance is done properly the class "p.news1" will
override the settings in the parent element selector "p" for those
particular settings.
KT
-----Original Message-----
From: Sven Axelsson [mailto:sven.axelsson@bokochwebb.se]
Sent: Friday, May 03, 2002 7:36 AM
To: smarty-general@lists.php.net; mpn@3dgamelink.com
Subject: RE: [SMARTY] Using Smarty for Dynamic CSS
Isn't the whole point with CSS that you don't change the style
selectors, you change the style definitions? Of course you can
do it like you say below, but wouldn't it be better to dynamically
generate the definitions like:
<style>
{$p_news}
{$p_whatever}
</style>
and just use the selectors directly in your html?
/sven axelsson
> -----Original Message-----
> From: MPN [mailto:mpn@3dgamelink.com]
> Sent: den 3 maj 2002 16:34
> To: smarty-general@lists.php.net
> Subject: RE: [SMARTY] Using Smarty for Dynamic CSS
>
>
> Thanks for the replies. :)
>
> I was thinking more along the lines of changing selectors
> within the body of the template. Say for instance, you give
> the user the option to change paragraph text size, and
> somewhere in your CSS you have something like p.news1
> {text-size: 1.0em; }... p.news5 {text-size: 1.5em; }. Then
> based on the user selection, the appropriate class selector
> is inserted into the template either by comparing a list of
> possible values from a config file, or by passing the
> variable directly to the template.
>
> Example:
>
> <p class="{$paraopt}">Blah blah</p> {* This assumes the entire
> selector is passed *}
>
> OR
>
> <p class="{#$paraopt#}">Blah blah</p> {* Where $paraopt is a
> simple identifier (a1, a2, ...) and the config file holds the
> actual CSS selector choices (news1, news2...) *}
>
>
>
> So the question is, what would be more efficient in terms of
> performance and code??
>
> KT
>
>
> -----Original Message-----
> From: Alan McFarlane [mailto:amcfarlane@bigfoot.com]
> Sent: Friday, May 03, 2002 6:20 AM
> To: mpn@3dgamelink.com; smarty-general@lists.php.net
> Subject: RE: [SMARTY] Using Smarty for Dynamic CSS
>
>
> Yup
>
> I use the following code:
>
> -- index.php --
> ...
> $tpl->assign("style", "default");
> ...
>
> -- index.tpl --
> ...
> <link rel="stylesheet" type="text/css"
> href="./styles/{$style}.css" />
> ...
>
>
> -----Original Message-----
> From: MPN [mailto:mpn@3dgamelink.com]
> Sent: 03 May 2002 04:02
> To: smarty-general@lists.php.net
> Subject: [SMARTY] Using Smarty for Dynamic CSS
>
>
> Has anyone explored the possibility of using smarty for
> dynamically changing CSS selectors?
>
> KT
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>