Add information to the course header by plugin

Add information to the course header by plugin

by Martin Mastny -
Number of replies: 3
Picture of Core developers Picture of Peer reviewers Picture of Testers
Hi,
what I'm looking for here is more of a general advice than a specific one.
I have a custom theme on my site which is based on Boost. I'm also currently developing a plugin, which performs some admin tasks (it's a tool_ kind of plugin) and saves some info about each course to the database.
I want to be able to display this info (just a couple of numbers) at each courses header for certain roles in Moodle.
So far so good. I can do it by modifying my own theme.

But what if I want to redistribute this plugin to someone else? This functionality is done by my tool_ plugin so shouldn't this plugin be responsible for modifying the 'current theme'(everyone can have different theme and I don't want to force them to use mine if they want to use my plugin) with its information?
I cannot find a way how to do this properly.
  • I tried creating my own theme, which serves only these changes and make it as a parent theme to my current - this does not work, cause course_header() function is also defined in my theme, so parent theme is not called.
  • Also, IMHO, tool_  plugins' renderer has no chance to alter course header.
  • There no hooks for plugin functions to inject something to the header
Anyone can give a direction how to do this?

Average of ratings: -
In reply to Martin Mastny

Re: Add information to the course header by plugin

by Hugo Ribeiro -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
You might want to look into course rating plugin https://moodle.org/plugins/tool_courserating

It can add content in course header despite the theme
Average of ratings: Useful (1)
In reply to Hugo Ribeiro

Re: Add information to the course header by plugin

by Martin Mastny -
Picture of Core developers Picture of Peer reviewers Picture of Testers
Thank you much Hugo, this helped me a lot.
I'm gonna share how this plugin achieves what I want to achieve in case someone has the same problem in the future.
Basically this plugin renders it's html (residing in renderer.php file) to one of possible places accessible by hooks. It renders it thru tool_courserating_before_footer plugin function, which renders it before the footer, but it is transferred to it's place right after page load by Javascript.

I don't know if Moodle these days should or should not work without JavaScript, cause without JavaScript this won't work. Anyway the whole plugin is useless without JavaScript and it's 2023 so one can expect that every browser "JavaScript ready".
For me, it's quite a nice solution and solves my problem.