我正在开发一个新的 Moodle 分配插件。如何在我的插件中包含自定义 CSS?我正在使用 Moodle 1.9.7。
提前致谢。
我正在开发一个新的 Moodle 分配插件。如何在我的插件中包含自定义 CSS?我正在使用 Moodle 1.9.7。
提前致谢。
只需将一个名为 styles.php 的文件添加到模块的文件夹中。该文件在解析时应输出 CSS 代码。
当页面的 CSS 布局构建时,Moodle 会进入每个模块的文件夹并查找该文件。
某些主题可以使用主题的 config.php 文件中的特殊设置来忽略这些文件
$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.
以下是该styles.php文件内容的简短示例:
/* 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;"} ?>
也许可以看看function print_header_simple()
定义在lib/weblib.php
.
如果您正在编写一个生成模块特定页面的模块,并且他们使用普通的 moodle 库,那么在生成页面时将一些内容$meta
添加到该<head>
部分中。
在lib/weblib.php
:
function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='', $cache=true, $button=' ', $menu='', $usexml=false, $bodytags='', $return=false) {
这意味着您可能希望在您的模块中包含以下内容:
$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);