Reputation: 1
I am trying to custom the classic theme to a theme (called theant theme) as a child theme of the theme boost.
I want to get all courses with their links in my moodle to display them as a menu in all of site. It looks like as the black menu bar in the picture. (https://i.sstatic.net/V46n[enter image description here](https://i.sstatic.net/oW8RI.png)t.png)
The menu bar is defined in the file 'theme/theant/templates/navbar.mustache' as follows
<nav class="fixed-top navbar navbar-bootswatch navbar-expand moodle-has-zindex">
<div class="fixed-subtop navbar" style="background-color: #333333; color: white;">
<ul>
{{#allcourses_menu}}
<li><a href="{{courselink}}"> "{{coursename}}"</a></li>
{{/allcourses_menu}}
</ul>
</div>
and the navbar.mustache is called by the template file 'theme/theant/templates/column.mustache' by code:
{{> theme_theant/navbar }}
In file 'theme/theant/renderers.php', I wrote (basing on the tutorial https://docs.moodle.org/dev/Extending_the_theme_custom_menu)
class theme_theant_core_renderer extends \core_renderer {
protected function render_allcourses_menu($allcourse_menu = null) {
global $CFG;
require_once($CFG->dirroot.'/lib/datalib.php');
$allcourses = get_courses();
$allcourses_menu = array();
foreach ($allcourses as $course) {
array_push($allcourses_menu, array("coursename"=>($course->shortname),
"courselink"=>(new moodle_url('/course/view.php', array('id' => $course->id)))));
}
return $allcourses_menu;
}
}
However, I don't know how to render $allcourses_menu to the template call it.
I try to put it in layout file 'theme/theant/layout/column.php' as follows
$allcourse_menu = $theme_theant_core_renderer::render_allcourses_menu();
....
$templatecontext = [
..........
'allcourses_menu'=> $allcourse_menu,
];
echo $OUTPUT->render_from_template('theme_theant/columns', $templatecontext);
But, I get a errors.
My questions are:
Thanks for your help. Cheers
Chon.
Upvotes: 0
Views: 415
Reputation: 31
"courselink"=>(new \moodle_url('/course/view.php', array('id' => $course->id))) . ''
$allcourse_menu = $theme_theant_core_renderer::render_allcourses_menu();
and I'm not sure how you've declared $theme_theant_core_renderer
but I would suggest using the class name itself directly if you want to call a static method just to minimize the code and clean it up.Upvotes: 0