How to test/edit theme without affecting the rest users

How to test/edit theme without affecting the rest users

by Tom Kappa -
Number of replies: 7

Hi, I did try my best to find the answer before posting but I did not.

I already have a Theme which is designed (Logos, texted, colors, footnotes etc). However, I wanna make some changes to make it look a bit fresher. Is there any way that I can make changes without being visible to other users? 

For instance; wanna try different colours, different logos, change headers-footnotes but if users that are logging in are able to see changes they gonna say that something is wrong and problematic. Well, obviously when I make my final choice and finalise it, i will make it public.

Thank you.

Current Moodle Version  3.1.12 

Average of ratings: -
In reply to Tom Kappa

Re: How to test/edit theme without affecting the rest users

by Hartmut Scherer -

Hi Tom,

My first choice for testing something is to mirror the life site to a local installation. I use Moodle on Bitnami and I test the theme in the local installation before I add the changes in the life site. 

My second choice is to change from your original theme to your test theme by using this URL: https://YOURSITE/?theme=clean and replace "YOURSITE" with the name of your site and "clean" with the name of your theme. This is only possible if your original theme and your test theme are different. You can only do this as a site admin. When you log in again, you will be back to your original theme for the site but you can use the same URL to switch to your test theme.

With kind regards,

Hartmut

Average of ratings: Useful (3)
In reply to Hartmut Scherer

Re: How to test/edit theme without affecting the rest users

by Jean-Roch Meurisse -
Picture of Core developers Picture of Plugin developers Picture of Testers

Maybe I'm wrong but I think that changing theme with url param can be done by any user and not just admins. 

And to complete Hartmut's post, when you are on pages already having parameters in the url (ex https://YOURSITE/course/view.php?id=4) add &theme=yourtheme rather than ?theme=yourtheme.

Kind regards

Jean-Roch


In reply to Tom Kappa

Re: How to test/edit theme without affecting the rest users

by Jean-Roch Meurisse -
Picture of Core developers Picture of Plugin developers Picture of Testers

Hi Tom,

You can try this. 

1. In your theme's layout files, add a class to the body tag (for example "themetests") but only when the logged in user is the admin user (or your user id).

if ($USER->id == youruserid) {
    global $USER;
    $extraclasses = array();
    $extraclasses[] = 'themetests';
    $OUTPUT->body_attributes($extraclasses);
}

You probably already have an $OUTPUT->body_attributes($something) call in your layout files, you just have to adapt it (it can take array or string as parameter)

2. Prefix all the css rules that you want to test with body.themetests

That should work!

Average of ratings: Useful (2)
In reply to Jean-Roch Meurisse

Re: How to test/edit theme without affecting the rest users

by Tom Kappa -

Hi again,

Thanks both for the replies. 

I have already tried Hartmut's idea and it is really incredible.

However @Jean-Roch Meurisse ,as I am willing to learn and explore new things, could you please give me further instructions on what exactly do you mean? 

In my theme's layout files there are 6 files (columns 1, columns 2, columns 3, embedded, maintenance and secure) all of them have the OUTPUT string...Which one is the correct?

Many thanks for your replies, once again.

In reply to Tom Kappa

Re: How to test/edit theme without affecting the rest users

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

Or instead of modifying six files, just create a class in the theme that overrides the 'core_renderer' class method 'body_attributes' and put the logic there along with calling the parent 'body_attributes' method as appropriate.

And '$OUTPUT' is not a string, it is a reference to the instantiated appropriate object of type 'core_renderer' being either the core one or the one in your theme.

And if my words don't make any sense, then read up on generic object orientation, PHP classes / objects and Moodle renderers.

Average of ratings: Useful (1)
In reply to Tom Kappa

Re: How to test/edit theme without affecting the rest users

by Jean-Roch Meurisse -
Picture of Core developers Picture of Plugin developers Picture of Testers

Hi again,

Gareth's method with a class overriding the core_renderer is cleaner of course wink

But if you do not have such a class so far, it may be easier for you to just use the layout file method (see my previous post) only on colums2.php which is the most widely used.

Then add css or scss rules of the kind:

body.themetest h1 {
    color: red 
}

This one will, for example, render course name in red in course home page.

Hope it helps

ps: if you cannot figure out how to adapt your columns2.php file, post the code snippet surrounding your $OUTPUT->bodyattributes($something) call and I will adapt it for you ;)

In reply to Jean-Roch Meurisse

Re: How to test/edit theme without affecting the rest users

by Tom Kappa -

Thanks for your replies. Very interesting! I did my job because of you. 


Cheers!