简体   繁体   English

在OctoberCMS中有条件地包含CSS文件

[英]Including css files conditionally in OctoberCMS

In OctoberCMS I can inject a CSS file into my page using: 在OctoberCMS中,我可以使用以下方法将CSS文件注入页面:

public function onRun()
{
    $this->addCss('http://yui.yahooapis.com/pure/0.6.0/grids-responsive-min.css');
}

I don't know though, how can I check the IE version in the code above? 我不知道,如何检查上面代码中的IE版本? What's the equivalent of the following CSS code in OctoberCMS? OctoberCMS中与以下CSS代码等效?

<!--[if lte IE 8]>
    <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/grids-responsive-old-ie-min.css">
<![endif]-->
<!--[if gt IE 8]><!-->
    <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/grids-responsive-min.css">
<!--<![endif]-->

The conditional markup you posted as a reference is a HTML conditional markup and therefore cannot be used in the PHP method onRun . 您发布为参考的条件标记是HTML条件标记,因此不能在PHP方法onRun

However, you can use the same conditional markup in your theme layout - or in a specific page. 但是,您可以在主题布局或特定页面中使用相同的条件标记。

Let's suppose you're using the demo theme. 假设您正在使用demo主题。

  • Go to themes/demo/layout/default.htm 转到themes/demo/layout/default.htm
  • Find the head section of your HTML document 查找HTML文档的head部分

Paste your code: 粘贴您的代码:

<!--[if lte IE 8]>
    <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/grids-responsive-old-ie-min.css">
<![endif]-->
<!--[if gt IE 8]><!-->
    <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/grids-responsive-min.css">
<!--<![endif]-->```

Remember to remove the addCss call from your onRun method to avoid adding the same stylesheet twice. 请记住从onRun方法中删除addCss调用,以避免两次添加相同的样式表。

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

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