Stylesheet for one layout only - Moodle 3.3

Stylesheet for one layout only - Moodle 3.3

by Dave Emsley -
Number of replies: 3

I want to create a very specific front page so I have created a layout for it.

I want the css to be subtly different so I have created a stylesheet JUST for this layout and placed it in the theme/style/ folder.

Within the layout file this...

    <style>
        #page {
            border: 1px solid red;
        }
        body {
            padding-top:0;
        }
    </style>

...works (obviously).

Take it out and put in a stylesheet and it doesn't work when included as...

    <link rel="stylesheet" type="text/css" href="../style/frontpage.css">


I can see that $CFG->theme gives the theme name, and $CFG->wwwroot so I can build a horrid looking link...

    <link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot."/theme/".$CFG->theme."/style/frontpage.css";?>">

Which works, no problem there.  However I'm certain there used to be a $themewww available or some such variable.  Is there, or do I just build my own as above?


Best Regards

Dave









Average of ratings: -
In reply to Dave Emsley

Re: Stylesheet for one layout only - Moodle 3.3

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

It would have been better had you added the body class .pagelayout-frontpage in front of all the styles you needed in order to restyle the  That way the styles could have been added to the Custom CSS section of your present theme's settings page.

However this is not answering your question.

Try this instead...

href="<?php echo new moodle_url('/theme/yourthemename/style/frontpage.css') ;?>"

In reply to Mary Evans

Re: Stylesheet for one layout only - Moodle 3.3

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Alternativly...
<style>
       .pagelayout-frontpage #page {
            border: 1px solid red;
        }
        body.pagelayout-frontpage {
            padding-top: 0;
        }
</style>
In reply to Dave Emsley

Re: Stylesheet for one layout only - Moodle 3.3

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Dave,

There is a thing called $CFG->themedir for when you place the theme in a folder that is not served by the web server.  In that case you need to serve the CSS manually using the pluginfile.php method.  In Essential for Moodle 3.1 look at the 'get_csswww()' method: https://github.com/gjb2048/moodle-theme_essential/blob/MOODLE_31/classes/toolbox.php#L59-L95 and see where it's called and look at: https://github.com/gjb2048/moodle-theme_essential/blob/MOODLE_31/lib.php#L29-L153.

Gareth