Jump to:

3445 Posts in 1031 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » including CSS in my module

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 498 Views
  • ismooth
    Avatar
    Community Member
    21 Posts

    including CSS in my module Link to this post

    I've made my own module, and now I want to add some css for better data presentation. I've got following file structure:

    - sigurnijiinternet
    -- css
    --- siginternet.css
    -- templates
    --- RedButtonPage.ss
    -- code
    --- RedButtonPage.php

    I've tried including

    <% require css(sigurnijiinternet/css/siginternet.css) %>

    into template file. Also with calling themedCSS(siginternet.css) function. I've tried calling Requirements class' css and themedCSS functions from init function of RedButtonPage_controller within RedButtonPage.php file:

    public function init() {
    parent::init();
    Requirements::themedCSS("siginternet");
    // Requirements::css("/www/sigurnijiinternet/css/siginternet.css");
    // parent::init();
    }

    Notice the variation on order of calling these functions. Furthermore, I've also tried changing user permissions on all mentioned files, but I never get any css included into the resulting html.

    Any hints?

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: including CSS in my module Link to this post

    You probably already found the following documentation for SS2.4 and SS3:
    - http://doc.silverstripe.org/framework/en/2.4/reference/requirements
    - http://doc.silverstripe.org/framework/en/reference/requirements

    <% require css(sigurnijiinternet/css/siginternet.css) %>

    Should work... You probaly also know to ?flush=1 if you change a template...

    Requirements::css("sigurnijiinternet/css/siginternet.css");

    Should work from your pagecontroller init() like you do (but not with the www though, but up from the root of your website)

    ThemedCSS now, that will only work if you place your css file in your theme...

  • ismooth
    Avatar
    Community Member
    21 Posts

    Re: including CSS in my module Link to this post

    martimiz,

    Yes, I've checked the documentation, and also tried flushing. I also tried various paths (absolute, relative...) to the css file. What I noticed is that if I don't Include all html code in template file (html, head, body tag....) then css doesn't get included. When I struct template file good, then it gets included - this is okay.

    But, I also noticed that some standard css files get included, like default theme's layout.css, js langugage file and so on. I've removed them with Requirements::clear. I guess that's why it's discouraged to include css, js and other files in controller's::init function.

    P.S. Maybe a notice could be added in documentation that full html code must be put in template file for template requirements to work?

    Cheers

    498 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.