简体   繁体   English

在CMSMS中缓存动态样式表

[英]Caching of dynamic stylesheets in CMSMS

I'm using CMS Made Simple. 我正在使用CMS变得简单。 I'm trying to include conditional Smarty code in my css stylesheet. 我正在尝试在css样式表中包含条件Smarty代码。

[[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 ). 该代码似乎正在工作(根据raduno的值,我得到红色或黄色背景)。 However, caching of css stylesheets seems to interfere with this approach. 但是,缓存css样式表似乎会干扰这种方法。 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 . 清除CMSMS服务器缓存后,在访问的第一页上选择的背景色是我在所有随后访问的页上也得到的背景色,而不管变量raduno的值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. 我正在使用CMSMS版本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!) 我的版本安装在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. 最简单的解决方法是使用内联css和Smarty,或使用jquery进行交换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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