Adding a Banner and Logo in Clean Theme with Upload Settings

Adding a Banner and Logo in Clean Theme with Upload Settings

by Kurt Russel Chua -
Number of replies: 7

Hello Moodle Community,

I am having trouble adding a banner and logo with the Clean Theme. I am using Moodle 3.0 and I have cloned the Clean Theme and named it "MyTheme" by following the instructions found in the Moodle docs. I would like to move the logo above the navigation bar and the banner on its place which is now as you can see in the image I have attached below. I would also like to add upload option or setting in the theme where you can separately change the logo and banner images which I have done so far but not yet finish. It would be a great help if you guys can give me some idea what to do.

Attachment cleanlogobanner.jpg
Average of ratings: -
In reply to Kurt Russel Chua

Re: Adding a Banner and Logo in Clean Theme with Upload Settings

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Moving to Themes forum...

In reply to Kurt Russel Chua

Re: Adding a Banner and Logo in Clean Theme with Upload Settings

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi,

You can do this quite easily since you have already cloned a theme, so at least you will be familiar with the files.

The way you do this is add this CSS to moodle/theme/mytheme/style/custom.css

body { 
margin-top: 100px;
background-image: url([[setting:logo]]);
background-position: 25px 25px;
background-repeat: no-repeat;
}

Also REMOVE this CSS

div.logo {
    background: url(setting:logo) no-repeat 0 0;
    display: block;
    float: left;
    height: 75px;
    margin: 0;
    padding: 0;
    width: 100%;
}

.dir-rtl div.logo {
    background: url(setting:logo) no-repeat 100% 0;
    display: block;
    float: right;
}

I am assuming you have got the banner where you want it to be?

Anyway...just try out the CSS I have given you and see how it looks.

The positioning of the logo in the body part of the page is set as 25px (from the left) 25px ( from the top) so just adjust those if you need to and alter the margin-top which is set as 100px which will give you a gap of 100px above the top navbar (hope that is what I think you mean).

Let me know how you get on.

Cheers

Mary

In reply to Mary Evans

Re: Adding a Banner and Logo in Clean Theme with Upload Settings

by Kurt Russel Chua -

Hello Mary,

I really appreciate your help on this. You see I just tested out your suggestion on changing the custom.css but the logo was still below the navigation bar which you can see in the image below. I think it moved up a little which I believe to be the css' doing if I'm not wrong.

Actually I have two problems regarding this discussion. First is how to move the logo above the navigation bar which is what you're trying to help me now. Second is how to create two separate 'div' for the logo and banner which is why you can see in the image below that the banner was not displayed because I can only set one 'div' per rendering because of my lack of knowledge in php and how Moodle works on rendering these html objects.

The files that I have modified so far to solve the second problem:

Added a configstoredfile setting in 'settings.php' to create additional image upload setting for banner

// Banner file setting.
$name = 'theme_mytheme/banner';
$title = get_string('banner','theme_mytheme');
$description = get_string('bannerdesc', 'theme_mytheme');
$setting = new admin_setting_configstoredfile($name, $title, $description, 'banner');
$setting->set_updatedcallback('theme_reset_all_caches');
$settings->add($setting);

Added a theme set 'banner' css in 'lib.php'

    // Set the background image for the banner.
$banner = $theme->setting_file_url('banner', 'banner');
$css = theme_mytheme_set_banner($css, $banner);

And change the html_writer class from 'logo' to 'banner' in public function context_header for the 'core_renderer.php'

    public function context_header($headerinfo = null, $headinglevel = 1) {

if ($this->should_render_logo($headinglevel)) {
$html = html_writer::tag('div', '', array('class' => 'banner'));
return $html;
}

return parent::context_header($headerinfo, $headinglevel);
}
I've done these things so far without knowing if they are right or wrong because I am still a beginner in php and new to Moodle. Please if you understand what I am trying to say then maybe you can shed some light to me on how I can move on from here.

Attachment logobannerclean.jpg
In reply to Kurt Russel Chua

Re: Adding a Banner and Logo in Clean Theme with Upload Settings

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Ok..

I will answer this more fully, and get back to you later. To get the CSS to work you need to Purge all cache as that hopefully is, or should be, working as desired.

Cheers

Mary

In reply to Mary Evans

Re: Adding a Banner and Logo in Clean Theme with Upload Settings

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi, 

Sorry I forgot to add a margin to the top of the .navbar this will make it drop down past the logo.

.navbar.navbar-fixed-top { margin-top: 100px;}

and then remove the margin-top from the body In the CSS I first posted.

I am sorry as this is difficult to do without a computer.

Looking at the changes made to the renderer, I would personally have left them out altogether, as it is just as easy to customise the layout files of your theme, and make it do what you want.

For example: If you copied the columns3.php and rename It frontpage.php and added it to the Frontpage file array in the $THEME->layouts of your theme's config.php, you could add the necesary HTML to add divs and CSS classes to style both the Logo and the Banner.

The code you added for the banner looks ok.but this will only work as Moodle developers want it to work. And if it changes then your banner may not work as you want it to.

At the end of the day it's all about changing the look of Moodle, not necessarily working with it.

i'll have a go at styling this and post some examples For you to try out.

Cheers

Mary

 

In reply to Mary Evans

Re: Adding a Banner and Logo in Clean Theme with Upload Settings

by Kurt Russel Chua -
Ok thank you very much Mary. I will try your suggestion on the css for the 'navbar' and make a frontpage.php by copying columns3.php. I will be back later to tell you about the outcome.
In reply to Kurt Russel Chua

Re: Adding a Banner and Logo in Clean Theme with Upload Settings

by Kurt Russel Chua -
Hi Mary,

I am very happy to say that your suggestions were correct. I was able to get the logo above the navigation bar and created new divs using the frontpage.php by adding a theme layout in the config.php. Thank you very much and God bless you Mary. smile