General developer forum

Settings in custom theme - same setting, two different settings pages?

 
Picture of Greg Holmes
Settings in custom theme - same setting, two different settings pages?
 

Developing my first custom Moodle theme. 

Is it possible to have the same theme setting appear in two different theme settings pages? 

For example, there's a XYZ settings page with toggle settings to denote the various places on the site where the XYZ should appear (or not appear), but there are also settings pages for those pages on the site where the XYZ could appear ... so it would be nice if the appropriate toggle setting could appear on both settings pages; access to the same single setting value on two different settings pages.

Does that make sense?

XYZ Settings Page

Show XYZ on:

Home page Y/N

Login page Y/N

etc.

Home Page Settings Page

Show XYZ on Home page Y/N


So the setting in italic above would really be the same setting, but you see it on two different settings pages. 

If that is not possible ... then how to add purely informational text to a settings page instead, instead of an actual setting?  So that I can indicate that for the relevant setting, you need to go over there to that other settings page to see it and change it?

Home Page Settings Page

Show XYZ on Home page 

You will find this setting on the XYZ settings page



 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Settings in custom theme - same setting, two different settings pages?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

I suspect the answer is: you can probably do it, even though it is not really supported, and it will mostly work.

Basically, you just define the setting twice, in your settings.php file, and add it to differenge pages.

I think the only think that won't work is this scenario:

  • Use the admin search feature to search for 'Home page'.
  • (Both copies of the setting will appear in the search results.)
  • Change the setting value using the first instance on the page, then click save.

I think what will happen (but I have not tried it) is that the value from the second instance of the setting on the page will always be used.

You need to test that, of course.

I you can live with that minor problem, then you should be OK. (Or, something more serious may break when you try it.)

 
Average of ratings: -
Picture of Greg Holmes
Re: Settings in custom theme - same setting, two different settings pages?
 

Tim, you are right - it doesn't crash or anything, but only the second instance of the setting in the UI actually works to change the setting. (Both display what it is currently set at though, which I guess has some utility.)

Because my theme is based on Boost, and the setting "pages" are tabs, therefore that problem is happening not only with an admin search, but all the time. Since both instances of the setting are really on the same web page (but different tabs). 

Hmm.

Have I missed a way to just put some arbitrary HTML on a settings page, where a setting would normally be? I mean, here's the actual setting code - but how could I put a similar looking section into the settings page that is not the actual setting, but rather just some text (saying that the user should go to the other tab to get to the actual setting)?

    // Show hide XYZ on home page toggle.
    $name = 'theme_blah/showxyzhomepage';
    $title = get_string('showxyzhomepage', 'theme_blah');
    $description = get_string('showxyzhomepage_desc', 'theme_blah');
    $default = 0;
    $setting = new admin_setting_configcheckbox($name, $title, $description, $default);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $page->add($setting);                                       
    
Does that make sense?  How to put a dummy "setting" on the settings page that is not actually a setting, but just some HTML?
 
Average of ratings: -
Gareth J Barnard
Re: Settings in custom theme - same setting, two different settings pages?
Core developersParticularly helpful MoodlersPlugin developers

Not making sense to me!

Is 'XYZ' a setting or a theme?

What is the specific problem that you're trying to solve that this solution addresses?

 
Average of ratings: -
Picture of Greg Holmes
Re: Settings in custom theme - same setting, two different settings pages?
 

Hi Gareth-

"XYZ" is just my shorthand here for a feature, a "thing" that I am using theme settings to control where it appears.

It could be anything ... for the sake of thinking about it, picture perhaps an advertisement. You need settings to say whether it should appear on the home page or not, on the login page or not, etc. 

There is one Settings page that is just for the XYZ settings - where should it appear?  A bunch of toggle switches.

But, also there are Settings pages for the home page, for the login page, etc. And I'd like those pages to have this toggle switch for that as well. 

So ideally, the Settings page for the login page would have a setting "Show the XYZ on the login page".  But the Settings page for the XYZ would also have that same setting, in its list of settings. The same setting would appear on two different settings pages. 

So you could come at it from two different directions. Like "hmm, where are all the places where XYZ should show (or is currently showing)", but also you might be coming instead from "hmm, what all should be showing on the login page"?

Does that help explain?


 
Average of ratings: -
Gareth J Barnard
Re: Settings in custom theme - same setting, two different settings pages?
Core developersParticularly helpful MoodlersPlugin developers

A theme defines its own settings and settings pages (for grouping).  I've never seen theme settings being added to other settings pages.

 
Average of ratings: -
Picture of Richard Oelmann
Re: Settings in custom theme - same setting, two different settings pages?
Core developersParticularly helpful MoodlersPlugin developersTesters

And even if you could put the same setting in multiple places, you'd have to do it by overriding the core of that page (eg home page settings), and what then if someone applies a different theme... Seems like a significant ongoing maintenance overhead to be considered there.

Its an interesting idea, but I'm not convinced of the user experience of finding the same setting in multiple locations, personally - and I am expressing only a personal opinion, no UX testing or any such data behind my opinion, just my own thoughts!

I'd probably go for a simpler route of finding an appropriate language string on the 'xyz' page (eg the home page settings) and customising that language string to provide a link back to the single settings page within your theme.

 
Average of ratings: -
Picture of Greg Holmes
Re: Settings in custom theme - same setting, two different settings pages?
 

I'm talking about settings "pages" (tabs) withing a theme based on Boost. 

It's all within one theme. 

 
Average of ratings: -