Solution to create a child theme of Essential that support a different logo/banner for certain courses and categories

Solution to create a child theme of Essential that support a different logo/banner for certain courses and categories

by Mari Cruz García -
Number of replies: 2

Hello,


For those who were not following the forum threat in which I enquired about the possibility of creating a child/clone theme of Essential so that I could customise a different banner for certain courses and categories, I attach the link to the solution:

https://www.dropbox.com/s/4wqir85bwdveo3k/essentials.zip?dl=0


Following Gareth's advice:

1) I have used the /essentials/ child them which is contained within Essential as a subfolder,

2)  Within the child theme Essentials, I have created a settings.php folder containing the text:

<?php


defined('MOODLE_INTERNAL') || die;

if ($ADMIN->fulltree) {


    // Logo file setting.

    $name = 'theme_essentials/logo';

    $title = get_string('logo','theme_essentials');

    $description = get_string('logodesc', 'theme_essentials');

    $setting = new admin_setting_configstoredfile($name, $title, $description, 'logo');

    $setting->set_updatedcallback('theme_reset_all_caches');

    $settings->add($setting);



    

}

3) Then in the file theme /Essentials/config.php  comment the lines:

$THEME->parents_exclude_sheets = array(

    'essential' => array(

        'essential-alternative',

        'essential-settings',

        'custom'

    )

); */


4) in the file /theme/essentials/lib.php

additing the part for uploading the logo from the admin menu settings of the theme 

function theme_essentials_process_css($css, $theme) {

  

     // Set the background image for the logo.

    $logo = $theme->setting_file_url('logo', 'logo');

    $css = \theme_essential\toolbox::set_logo($css, $logo);

   

5) and to use the rest of the settings from essential, we change the variable to true;

$usingessentialsettings = true;


6) Finally, in the same theme/essentials/lib.php file we add this part to display only the logo (in my case I didn't want alternative text):

function theme_essentials_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {

    static $theme;

    if (empty($theme)) {

        $theme = theme_config::load('essentials');

    }

    if ($context->contextlevel == CONTEXT_SYSTEM) {

        if ($filearea === 'logo') {

            return $theme->setting_file_serve('logo', $args, $forcedownload, $options);

        } 

    else {

        send_file_not_found();

        }

    }

}


7) We add the language strings corresponding to the settings menu for the logo at themes/essentials/lang/en/theme_essentials.php (for English language):

$string['logo'] = 'Logo';

$string['logodesc'] = 'Enter the URL to an image to use as the logo for this site. Should be http://www.yoursite.com/path/to/logo.png';


Average of ratings: -
In reply to Mari Cruz García

Re: Solution to create a child theme of Essential that support a different logo/banner for certain courses and categories

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Thanks for the post Mari that demonstrates my guess: https://moodle.org/mod/forum/discuss.php?d=322405#p1294629 is correct.  Looking at point seven, you've used the same text as in the Essential theme language file, thus you don't need it and then just change the settings 'get_string' to use 'theme_essential' instead.

In reply to Gareth J Barnard

Re: Solution to create a child theme of Essential that support a different logo/banner for certain courses and categories

by Mari Cruz García -

Thanks for the final comment, Gareth. I will amend the language files accordingly.