How to change the image in the logo using a custom theme in Totara?

|
| By Webner

Let us suppose, in Totara we have a custom theme named “test”. Now, we will discuss how will we display a custom logo on our website. There are three steps to change your site logo:

  1. Firstly, you will have to override the standard site_logo() function into your theme. To do this, create a function render_site_logo() in the “test/classes/renderer.php” file as:
    public function render_site_logo() {
    global $OUTPUT, $CFG, $SITE;
    $templatecontext = array(
    'siteurl' => $CFG->wwwroot . '/',
    'shortname' => $SITE->shortname
    );
    $templatecontext['logourl'] = $OUTPUT->pix_url('logo_copy', ‘’); //”logo_copy.png” should be existed in “pix” folder of your theme
    $templatecontext['logoalt'] = ‘<logoalt_string>’;
    return $this->render_from_template('test/site_logo',
    $templatecontext); //it will call the site_logo.mustache file
    }
  2. Now, Create a new file named “site_logo.mustache” into the “templates” folder and paste the below contents into that file.
    <h1 id="logo" class="site-logo">
    <a class="navbar-brand" href="{{siteurl}}">
    {{#logourl}}<img class="logo img-responsive" src="{{logourl}}" {{#logoalt}}alt="{{.}}"{{/logoalt}} />{{/logourl}}
    {{^logourl}} {{/logourl}}
    <span class="sr-only">{{shortname}}</span>
    </a>
    </h1>
  3. Now, call this custom logo in the header layout of your Totara custom theme. Place the below code in the appropriate location into the “test/layout/partials/header.php” file.
    <div class="navbar-header pull-left">
    render_site_logo(); ?>