代码之家  ›  专栏  ›  技术社区  ›  konrad

Silverstripe要求::css()不包括css

  •  0
  • konrad  · 技术社区  · 7 年前

    我尝试为某个页面包含自定义css文件。我使用 Requirements::css() PageController中的方法 init() ,但我也尝试了模板标记: <% require css(mytheme/css/aa.css) %> . 结果是,生成的页面中没有指向该文件的链接。没有报告错误,只是没有影响。这个 初始化() 方法被调用,我可以从它内部触发日志。

    class AaPage_Controller extends Page_Controller {
    
        public function init () {
            parent::init();
            Requirements::css("mytheme/css/aa.css");
        }
    
    }
    

    我现在在兜圈子,谁有更多的SS经验,可以建议一种方法来调试这个问题吗?

    3 回复  |  直到 7 年前
        1
  •  4
  •   wmk    7 年前

    令人遗憾的是,新的API文档不再显示对方法参数的解释,希望很快得到修复。

    如果你 look at the code (使用合适的IDE很容易,因为您可以跳转到正在调用的方法)您将看到:

    /**
     * Register the given stylesheet into the list of requirements.
     *
     * @param string $file  The CSS file to load, relative to site root
     * @param string $media Comma-separated list of media types to use in the link tag
     *                      (e.g. 'screen,projector')
     */
    public static function css($file, $media = null) {
        self::backend()->css($file, $media);
    }
    

    要加载的CSS文件, 相对于站点根

    由于您的主题不在站点根目录下,您需要以下内容:

    Requirements::css("themes/mytheme/css/aa.css");
    
        2
  •  1
  •   bummzack    7 年前

    我建议您使用 Requirements::themedCSS . 所以要包括 aa.css ,您可以执行以下操作:

    Requirements::themedCSS('aa');
    

    在模板中:

    <% require themedCSS("aa") %>
    

    这样,它将自动在模板文件夹中搜索请求的资源。

        3
  •  0
  •   Lamin Barrow    7 年前

    你有没有 head 模板文件中的区域?您需要确保 .ss 在Silverstipe将您的需求css文件添加到该文件之前,该文件具有熊最小值。需要提供如下所示的基本html框架。

    <html>
    <head>
        <title>Page title</title>
    </head>
    <body>
    </body>
    </html>