Moodle: add custom html to settings block (block_settings)

Trabla: add custom html to settings block (block_settings)

Moodle eLearning LMS add custom html to settings block (block_settings) - codingtrabla tutorial screenshot 1
This is default moodle settings block. You can see it if login as admin.
Trabla is to add custom html to this block - to get image below.
Moodle eLearning LMS add custom html to settings block (block_settings) - codingtrabla tutorial screenshot 2


Solving:
1. Open .php script file:
...\moodle\blocks\settings\block_settings.php

2. Find code:

// only do search if you have moodle/site:config
        if (!empty($this->content->text)) {
            if (has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) ) {

                $this->content->footer = $renderer->search_form(new moodle_url("$CFG->wwwroot/$CFG->admin/search.php"), optional_param('query', '', PARAM_RAW));

            } else {
                $this->content->footer = '';
            }

            if (!empty($this->config->enabledock) && $this->config->enabledock == 'yes') {
                user_preference_allow_ajax_update('nav_in_tab_panel_settingsnav'.block_settings::$navcount, PARAM_INT);
            }
        }

3. Write custom  code and save file:

 // only do search if you have moodle/site:config
        if (!empty($this->content->text)) {
            if (has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) ) {

                $custom_html = '
                    <a href="google.com">Google</a>
                ';

                $this->content->text = $custom_html . $this->content->text;


                $this->content->footer = $renderer->search_form(new moodle_url("$CFG->wwwroot/$CFG->admin/search.php"), optional_param('query', '', PARAM_RAW));

            } else {
                $this->content->footer = '';
            }

            if (!empty($this->config->enabledock) && $this->config->enabledock == 'yes') {
                user_preference_allow_ajax_update('nav_in_tab_panel_settingsnav'.block_settings::$navcount, PARAM_INT);
            }
        }


4. Update page in browser:


No comments:

Post a Comment