将自定义 CSS 添加到新的 Moodle 作业中

发布于 2024-08-19 22:53:26 字数 84 浏览 5 评论 0原文

我正在开发一个新的 Moodle 分配插件。 如何将自定义 CSS 添加到我的插件中? 我正在使用 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 in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

漫漫岁月 2024-08-26 22:53:26

只需将一个名为 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;"} ?>

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;"} ?>
何必那么矫情 2024-08-26 22:53:26

也许可以看看lib/weblib.php中定义的function print_header_simple()

如果您正在编写一个生成模块特定页面的模块,并且它们使用普通的 Moodle 库,则将 $meta 中的内容添加到 部分,同时正在生成页面。

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);

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=' ', $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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文