Gradebook report plugin html_table vs. templates

Gradebook report plugin html_table vs. templates

by Laurent Duchesne -
Number of replies: 1

Dear All,

I’m writing a gradebook report plugin (under grade/report/myreport) and I have a question concerning the page layout. Most of the code that render tables in Moodle 3 seems to use the html_table() object to output HTML content. From reading this page, it seems Mustache templates are the way to go from now on:

https://docs.moodle.org/dev/Templates

Is that right?

Assuming so, I created a template under grade/report/myreport/templates/main.mustache and called it using the following:

$OUTPUT->render_from_template("grade/report/myreport/main", $context);

But I get the following error:

Templates cannot be placed in sub directories

Does that mean that my template must be installed directly under grade/templates? (Which does not exist in my Moodle 3.0 installation.) It feels wrong to put the template outside my plugin directory so I wanted to ask others what they do in that situation. I can still fall back to using an html_table object in my plugin but if it’s going to disappear, I guess I should not.

Regards,

Laurent

Average of ratings: -
In reply to Laurent Duchesne

Re: Gradebook report plugin html_table vs. templates

by Laurent Duchesne -

For anyone having the same question, after digging into lib/classes/component.php, I found out that the component can be the following:

gradereport_myreport

So you can have this template file:

grade/report/myreport/templates/main.mustache

And render it using the following:

echo $OUTPUT->render_from_template("gradereport_myreport/main", $context);

Hope this helps someone.

Regards,

Laurent