Cloning More Theme?

Cloning More Theme?

by Simon Ward -
Number of replies: 15

Hi,


I've read these: 

https://moodle.org/mod/forum/discuss.php?d=272652

https://docs.moodle.org/dev/Cloning_a_theme

https://docs.moodle.org/dev/Themes_2.2_how_to_clone_a_Moodle_2.2_theme

As well as some other references to cloning themes, but I'm not having any joy.


I've tried copying the "More" folder, and replacing any instance of "more" with a new name within the files within, but I'm not seeing my "clone" within the Theme Selector.


Does anyone know of any other information for specifically cloning the "More" theme?

I've been able to create a look simply by editing the More theme, but want to be able to create variations of it...


Cheers in advance...

Average of ratings: -
In reply to Simon Ward

Re: Cloning More Theme?

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

More is no different than any other theme when it comes to cloning it, so I am guessing you have missed off some important things, like installing it?

It will not show up in the Theme selector if it is not installed. On the other hand if it installed and was a success then things are looking good, so it may be you forgot to change the pluginname in theme/yourmorethemclonename/lang/en/theme_yourmorethemeclonename.php

Cheers

Mary

In reply to Mary Evans

Re: Cloning More Theme?

by Simon Ward -

It was just the installation I needed to do, cheers.


I have another question:

Is it possible to specify "default" logo images?

So that when the theme is installed, they are already there. At the moment I have to upload the image via the settings page. And when I do this, I'm not sure where it is saved.

Inspecting the element gives the following address: http://localhost/pluginfile.php/1/theme_mytheme/logo/1416226149/my_logo.png

I can't see this in the Moodle folder, so I'm assuming it's in the database?


Is it possible to store and use the logo image from the theme's "pix" folder?

I can see this in the Custom CSS file:

background: url(setting:logo)

Can I change this to point to an image in the pix folder?

In reply to Simon Ward

Re: Cloning More Theme?

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

Yes you can, you just remove the [setting:logo] from the url([setting:logo]) in the css and replace with:

url([[pix:theme|logo]])

providing your logo image is placed in your newly named theme's pix directory.

eg: theme/yourthemesname/pix/logo.png
PS: It can be .jpg or .gif makes no difference as the name is only used not the extension type.

In reply to Mary Evans

Re: Cloning More Theme?

by Simon Ward -

Thank you again for the pointers Mary.


I've changed that in the Custom CSS file and made sure the file is in the Pix folder, but the logo is not coming up by default.

background: url([[pix:theme|logo]])


The logo upload box on the settings page is empty.


Any ideas?

In reply to Simon Ward

Re: Cloning More Theme?

by Simon Ward -

OK, it's getting late here (Aus).

Close, but not quite there yet.


For some reason, when I modify the Custom CSS file, the logo doesn't appear by default.

I also need to increase the height to 100px, but don't know if this is working until the logo appears.

Now I'm a "clone master" I tried doing this on a new theme to make sure nothing was being cached. But still no joy.


I'll look at it with fresh eyes tomorrow, but if anyone has any pointers, that'd be great.



Cheers again in advance.

In reply to Simon Ward

Re: Cloning More Theme?

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

Sorry...there is a better way to fix the logo by adding a fall back in the form of a 'replacement' style if the setting is empty.

Locate your theme's lib.php file and find these lines...apart from the theme name (hilighted in yellow)  which needs to be your theme's name and add the replacement code highlighted in green.

Also scrap the other idea about changing the CSS put that as it was with the setting:logo in the url.

Hope this helps?

Cheers

Mary

/**
 * Adds the logo to CSS.
 *
 * @param string $css The CSS.
 * @param string $logo The URL of the logo.
 * @return string The parsed CSS
 */
function theme_yourthemename_set_logo($css, $logo) {
    $tag = 'setting:logo';
    $replacement = $logo;
    if (is_null($replacement)) {
        $replacement = $theme->pix_url('logo', 'theme');
    }

    $css = str_replace($tag, $replacement, $css);

    return $css;
}

In reply to Mary Evans

Re: Cloning More Theme?

by Simon Ward -

Umm, something isn't quite right. I'm either missing something or haven't done this right.


I have a version of my theme - everything installs correctly, except the logo.


I cloned this theme, and changed:

$replacement = ''; to $replacement = $theme->pix_url('logo', 'theme');

Everything installs OK (although the logo isn't displayed on the initial settings screen), but when I apply the theme, the whole site has a melt down (like there's no CSS at all).


On another clone, I also tried (purely guessing):

$replacement = ''; to $replacement = $theme->pix_url('logo', 'theme_tgs_test3');

The same as above happens, css meltdown.


tgs_test3 is the name of the last theme I tried. tgs_test4 will be the next one to try, and so on (creating a new theme each time to make sure everything is installed fresh).

The logo is called "logo.png" and is stored in the theme's pix folder.


Thanks again in advance. 

In reply to Simon Ward

Re: Cloning More Theme?

by Simon Ward -

Having read "Note that'theme' above means the word theme, and not the name of your theme" from https://docs.moodle.org/dev/Using_images_in_a_theme

I realise my second attempt/guess above was wrong.


I just can't see why what Mary is suggesting isn't working/breaking all CSS.

In reply to Simon Ward

Re: Cloning More Theme?

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

have a cloned theme of More and have found that it too looses all the CSS. So rather than think it is a problem you have created I am thinking it is a BUG in the LESS compiler which is what Moore uses to create it's own css.

That said, however, did you also reinstate the setting:logo in the custom CSS file? The one which you changed first time round?

Also you are adding the replacement into your new theme's lib.php file?

If the answer to all that is YES! then try debugging. Go to Site Administration > Development > Debugging

and enable DEVELOPER mode in the top drop-down box on that page. Leave the error message setting to be on the page, this then gives you a clear message if there is an error in the coding. Missing off ; or a } is leathal in PHP.

Cheers

Mary

In reply to Mary Evans

Re: Cloning More Theme?

by Simon Ward -

"did you also reinstate the setting:logo in the custom CSS file? The one which you changed first time round?"

Yes


"Also you are adding the replacement into your new theme's lib.php file?"

Yes


So I'll give debugging a go.

Any idea when to expect an error? During installation? When when the page first loads after applying the theme?

In reply to Simon Ward

Re: Cloning More Theme?

by Simon Ward -

I've enabled Debugging, but aren't seeing any errors (have just installed and applied the theme) . Where would I see them?

In reply to Simon Ward

Re: Cloning More Theme?

by Simon Ward -

Just one more observation (for what it's worth):


By default, the More theme uses a background, and when theme (or a clone) is installed, it is displayed in the settings box automatically.

Nothing I've done so far has displayed the logo in the logo settings box automatically.

In reply to Simon Ward

Re: Cloning More Theme?

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

Thanks fr the theme...I'm just testing it now.

As a last minute thing...try a Purge all cache see if that fixes anything?

Just to clarify, in the replacement where it says $replacement = $theme->pix_url('logo', 'theme');

The word 'theme' in this case is coded as 'theme' and as such does not need the theme name adding.