Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Talk:Blocks: Difference between revisions

From MoodleDocs
(moodle 2 code for customizing block's title)
mNo edit summary
Line 9: Line 9:
<code php>
<code php>
     $mform->addElement('text', 'config_title', get_string('configtitle', 'block_simplehtml'));
     $mform->addElement('text', 'config_title', get_string('configtitle', 'block_simplehtml'));
     $mform->setDefault('config_text', get_string('simplehtml', 'block_simplehtml'));
     $mform->setDefault('config_title', get_string('simplehtml', 'block_simplehtml'));
     $mform->setType('config_title', PARAM_MULTILANG);
     $mform->setType('config_title', PARAM_MULTILANG);
</code>
</code>

Revision as of 03:46, 7 July 2011

Moodle 2.0


The Specialists

To customize the block's title under Moodle 2.0 the following code can be used:

edit_form.php

   $mform->addElement('text', 'config_title', get_string('configtitle', 'block_simplehtml'));
   $mform->setDefault('config_title', get_string('simplehtml', 'block_simplehtml'));
   $mform->setType('config_title', PARAM_MULTILANG);

simplehtml/lang/en/block_simplehtml.php

 $string['configtitle'] = 'Title of simple html';

block_simplehtml.php

 function specialization() {
   $this->title = isset($this->config->title) ? format_string($this->config->title) : format_string(get_string('simplehtml', 'block_simplehtml'));
   }

The specialization function is copied from the html block. Different standard blocks seem to implement this differently. It would be nice if someone can explain what's happening in this specialization function.

--Roel Cantada 11:43, 7 July 2011 (WST)