public static function setup_for_template($pagecontextid, moodle_url $url, $template = null, $subtitle = '',
                                              $returntype = null) {
        global $PAGE, $SITE;

        $pagecontext = context::instance_by_id($pagecontextid);
        $context = $pagecontext;
        if (!empty($template)) {
            $context = $template->get_context();
        }

        $templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
        $templateurl = null;
        if ($template) {
            $templateurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', [
                'templateid' => $template->get('id'),
                'pagecontextid' => $pagecontextid
            ]);
        }

        $returnurl = $templatesurl;
        if ($returntype != 'templates' && $templateurl) {
            $returnurl = $templateurl;
        }

        $PAGE->navigation->override_active_url($templatesurl);
        $PAGE->set_context($pagecontext);

        if (!empty($template)) {
            $title = format_string($template->get('shortname'), true, array('context' => $context));
        } else {
            $title = get_string('templates', 'tool_lp');
        }

        if ($pagecontext->contextlevel == CONTEXT_SYSTEM) {
            $heading = $SITE->fullname;
        } else if ($pagecontext->contextlevel == CONTEXT_COURSECAT) {
            $heading = $pagecontext->get_context_name();
        } else {
            throw new coding_exception('Unexpected context!');
        }

        $PAGE->set_pagelayout('admin');
        $PAGE->set_url($url);
        $PAGE->set_title($title);
        $PAGE->set_heading($heading);

        if (!empty($template)) {
            $PAGE->navbar->add($title, $templateurl);
            if (!empty($subtitle)) {
                $PAGE->navbar->add($subtitle, $url);
            }

        } else if (!empty($subtitle)) {
            // We're in a sub page without a specific template.
            $PAGE->navbar->add($subtitle, $url);
        }

        return array($title, $subtitle, $returnurl);
    }
public static function setup_for_template($pagecontextid, moodle_url $url, $template = null, $subtitle = '',
                                              $returntype = null) {
        global $PAGE, $SITE;

        $pagecontext = context::instance_by_id($pagecontextid);
        $context = $pagecontext;
        if (!empty($template)) {
            $context = $template->get_context();
        }

        $templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
        $templateurl = null;
        if ($template) {
            $templateurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', [
                'templateid' => $template->get('id'),
                'pagecontextid' => $pagecontextid
            ]);
        }

        $returnurl = $templatesurl;
        if ($returntype != 'templates' && $templateurl) {
            $returnurl = $templateurl;
        }

        $PAGE->navigation->override_active_url($templatesurl);
        $PAGE->set_context($pagecontext);

        if (!empty($template)) {
            $title = format_string($template->get('shortname'), true, array('context' => $context));
        } else {
            $title = get_string('templates', 'tool_lp');
        }

        if ($pagecontext->contextlevel == CONTEXT_SYSTEM) {
            $heading = $SITE->fullname;
        } else if ($pagecontext->contextlevel == CONTEXT_COURSECAT) {
            $heading = $pagecontext->get_context_name();
        } else {
            throw new coding_exception('Unexpected context!');
        }

        $PAGE->set_pagelayout('admin');
        $PAGE->set_url($url);
        $PAGE->set_title($title);
        $PAGE->set_heading($heading);

        if (!empty($template)) {
            $PAGE->navbar->add($title, $templateurl);
            if (!empty($subtitle)) {
                $PAGE->navbar->add($subtitle, $url);
            }

        } else if (!empty($subtitle)) {
            // We're in a sub page without a specific template.
            $PAGE->navbar->add($subtitle, $url);
        }

        return array($title, $subtitle, $returnurl);
    }
public static function setup_for_template ( $ pagecontextid , moodle_url $ url , $ template = null , $ subtitle = '' , $ returntype = null ) { global $ PAGE , $ SITE ; $ pagecontext = context :: instance_by_id ( $ pagecontextid ) ; $ context = $ pagecontext ; if ( ! empty ( $ template ) ) { $ context = $ template -> get_context ( ) ; } $ templatesurl = new moodle_url ( '/admin/tool/lp/learningplans.php' , array ( 'pagecontextid' => $ pagecontextid ) ) ; $ templateurl = null ; if ( $ template ) { $ templateurl = new moodle_url ( '/admin/tool/lp/templatecompetencies.php' , [ 'templateid' => $ template -> get ( 'id' ) , 'pagecontextid' => $ pagecontextid ] ) ; } $ returnurl = $ templatesurl ; if ( $ returntype != 'templates' && $ templateurl ) { $ returnurl = $ templateurl ; } $ PAGE -> navigation -> override_active_url ( $ templatesurl ) ; $ PAGE -> set_context ( $ pagecontext ) ; if ( ! empty ( $ template ) ) { $ title = format_string ( $ template -> get ( 'shortname' ) , true , array ( 'context' => $ context ) ) ; } else { $ title = get_string ( 'templates' , 'tool_lp' ) ; } if ( $ pagecontext -> contextlevel == CONTEXT_SYSTEM ) { $ heading = $ SITE -> fullname ; } else if ( $ pagecontext -> contextlevel == CONTEXT_COURSECAT ) { $ heading = $ pagecontext -> get_context_name ( ) ; } else { throw new coding_exception ( 'Unexpected context!' ) ; } $ PAGE -> set_pagelayout ( 'admin' ) ; $ PAGE -> set_url ( $ url ) ; $ PAGE -> set_title ( $ title ) ; $ PAGE -> set_heading ( $ heading ) ; if ( ! empty ( $ template ) ) { $ PAGE -> navbar -> add ( $ title , $ templateurl ) ; if ( ! empty ( $ subtitle ) ) { $ PAGE -> navbar -> add ( $ subtitle , $ url ) ; } } else if ( ! empty ( $ subtitle ) ) { // We're in a sub page without a specific template. $ PAGE -> navbar -> add ( $ subtitle , $ url ) ; } return array ( $ title , $ subtitle , $ returnurl ) ; }
Set-up a template page.

Example:
list($title, $subtitle) = page_helper::setup_for_template($pagecontextid, $url, $template, $pagetitle);
echo $OUTPUT->heading($title);
echo $OUTPUT->heading($subtitle, 3);

@param  int $pagecontextid The page context ID.
@param  moodle_url $url The current page.
@param  \core_competency\template $template The template, if any.
@param  string $subtitle The title of the subpage, if any.
@param  string $returntype The desired return page.
@return array With the following:
- Page title
- Page sub title
- Return URL
Set - up a template page .