开发者

Adding custom CSS into a new Moodle assignment

开发者 https://www.devze.com 2022-12-18 23:06 出处:网络
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.

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 i开发者_Go百科n advance.


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;"} ?>


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 <head> section while the page is being generated.

in lib/weblib.php:

function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='', $cache=true, $button='&nbsp;', $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 = '<link rel="stylesheet" type="text/css" href="'.$extra_css.'" />';
print_header_simple($mytitle, "", $navigation, "", "", true, "", navmenu($course), '', $extra_css_meta);
0

精彩评论

暂无评论...
验证码 换一张
取 消