Regis Zaleman
Regis Zaleman

Reputation: 3250

How to create custom markup in Moodle theme settings?

I need to create a list of elements in a Moodle 2.x theme setting for which I will enable drag and drop re-ordering using Moodle's included YUI. My problem is that I don't know how to add my custom HTML/JS with a custom theme setting. I can only find documentation about adding settings with the pre-defined functions offered by Moodle, like admin_setting_configtext or admin_setting_configselect or admin_setting_configtextarea etc... How do I go about creating my own markup and use my own javascript in a theme setting page? Thanks!

Upvotes: 3

Views: 1034

Answers (1)

Mark
Mark

Reputation: 491

You can create a custom page using Moodle, remember to require the config and set up the page:

require('../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
//page definition
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_url('/theme/your_theme/admin/manage.php');
$PAGE->set_pagetype('theme_name_manage');
$PAGE->set_title('Manage your theme');
$PAGE->set_heading('Manage your theme');
echo $OUTPUT->header();
//Page content
echo $OUTPUT->footer();

From this page you can define whatever setup or configuration you want. Finally you will want to add this page to the site admin navigation. Make sure you have a settings.php in the root directory of your theme and within that file you'll be wanting something like this:

if ($hassiteconfig) { // needs this condition or there is error on login page
    $ADMIN->add('themes', new admin_externalpage('theme_name', 
        'Manage Theme XYZ', 
        $CFG->wwwroot."/theme/name/admin/manage.php", 
        'moodle/site:config'));
}

Themes being the reference for the "themes" admin menu I figure you probably want to add this to. Remember that you should be using get_string in the above examples instead of hard-coding strings.

Upvotes: 3

Related Questions