简体   繁体   中英

Caching of dynamic stylesheets in CMSMS

I'm using CMS Made Simple. I'm trying to include conditional Smarty code in my css stylesheet.

[[if $raduno eq '1']]
  [[assign var='bgcolor' value='#bc3516']] /* red */
[[else]]
  [[assign var='bgcolor' value='#f3c127']] /* yellow */
[[/if]]

body {
    background-color:  [[$bgcolor]];
    ...
}

The code seems to be working (I get a red vs. yellow background depending on the value of raduno ). However, caching of css stylesheets seems to interfere with this approach. The background color selected on the first page visited after clearing the CMSMS server cache is the one I also get on all subsequently visited pages, regardless of the value of variable raduno .

Is it possible to cache the stylesheet depending on the value of a variable? (If so, automatically or manually?)

The problem is currently resolved by having two separate stylesheets. However, this makes maintainance difficult. Also, disabling the cache is not an option here --- the template using the two stylesheets is used for the whole site.

I am using CMSMS version 1.10.3. I realize that upgrading might help, but I haven't found any indications that this is the case in the changelogs. (And my version is installed on opensourcecms.com!)

No, the only way to do this would be to avoid caching the stylesheets, which would not be a good idea. The simplest workaround would be to use inline css and Smarty, or do the swap with jquery.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM