Skip to content

Instantly share code, notes, and snippets.

@frumbert
Last active March 15, 2022 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frumbert/221536dac8f65a5f853b939873dbba24 to your computer and use it in GitHub Desktop.
Save frumbert/221536dac8f65a5f853b939873dbba24 to your computer and use it in GitHub Desktop.
Sample theme template renderer for filter_units (https://github.com/frumbert/filter_units)
{{>theme_mytheme/inc_start}}
<div id="page" class="container-fluid">
{{{ output.full_header }}}
<div id="page-content" class="row">
<div id="region-main-box" class="col-12">
{{#hasregionmainsettingsmenu}}
<div id="region-main-settings-menu" class="d-print-none">
<div> {{{ output.region_main_settings_menu }}} </div>
</div>
{{/hasregionmainsettingsmenu}}
<section id="region-main">
<div class="card">
<div class="card-body">
{{#hasregionmainsettingsmenu}}
<div class="region_main_settings_menu_proxy"></div>
{{/hasregionmainsettingsmenu}}
{{#coursehome}}
{{> core/single_button }}
{{/coursehome}}
{{{ output.course_content_header }}}
{{{ output.main_content }}}
{{{ output.course_content_footer }}}
</div>
</div>
{{{ output.activity_navigation }}}
</section>
</div>
</div>
</div>
{{>theme_mytheme/inc_end}}
$templatecontext = [
'sitename' => format_string($SITE->shortname, true, ['context' => context_course::instance(SITEID), "escape" => false]),
'output' => $OUTPUT,
'sidepreblocks' => $blockshtml,
...
'coursehome' => theme_mytheme_coursehome_button($OUTPUT)
];
echo $OUTPUT->render_from_template('theme_mytheme/columns2', $templatecontext);
function theme_mytheme_coursehome_button($output, $consume = true) {
global $SESSION;
if (isset($SESSION->coursehome)) {
$coursehomeurl = new \moodle_url($SESSION->coursehome);
if ($consume) unset($SESSION->coursehome);
$url = new \single_button($coursehomeurl, get_string('returntocourse', 'filter_units'), 'get', true);
$data =$url->export_for_template($output);
return $data;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment