views:

215

answers:

2

I'm working on a new Moodle Assignment plugin. How can I include a custom CSS to my plugin? I'm using Moodle 1.9.7.

Thanks in advance.

A: 

Perhaps could take a look at the function print_header_simple() defined in lib/weblib.php.

If you are writing a module which generates module specific pages, and they use the normal moodle libraries then stick something in $meta to be added to the section while the page is being generated.

in lib/weblib.php: function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='', $cache=true, $button=' ', $menu='', $usexml=false, $bodytags='', $return=false) {

This means that you probably want something like the following in your module:

$extra_css = $CFG->wwwroot.'/theme/SUPA4/supa_report.css'; $extra_css_meta = ''; print_header_simple($mytitle, "", $navigation, "", "", true, "", navmenu($course), '', $extra_css_meta);

digitalsean
I'll check this. Thanks.
Roberto Aloi
+1  A: 

just add a file called styles.php into the Module's folder. the file should output CSS code when it is parsed.

Moodle goes into each Module's folder and looks for that file, when the page's CSS layout is constructed.

Some themes can ignore these files using a special setting in the theme's config.php file

$THEME->modsheets = true;

/// When this is enabled, then this theme will search for
/// files named "styles.php" inside all Activity modules and
/// include them.   This allows modules to provide some basic
/// layouts so they work out of the box.
/// It is HIGHLY recommended to leave this enabled.

here is a short sample of what could be the content of this styles.php file:

/* simple CSS code */ 
.left { float:left; }

/* php that generate CSS code */
< ?php if ( right_to_left() ) {echo ".right:text-align:left;"} 
else {echo ".right:text-align:right;"} ?>
nadavkav
Thanks. Having a .php file for style sounds like an heresy to me, but that's the way Moodle does it and we need to live with it.
Roberto Aloi
well, it is only meant to easy the generating of CSS code for the php programmer. that can branch on output-ing different CSS code for different languages (RTL or LTR). eventually, all these files are gathered into one file and the mime type is set to "text/css". so the browser does not know it was a php file, originally. i think it is kinda nice :-)
nadavkav