0

I am new in Moodle. I have requirement to add dynamic help text in help icon created using $mform->addHelpbutton(); function. But we are not able to do this.

Can anyone tell me any another way to pass the dynamic string in moodles form help icon.

3
  • can you provide some code?
    – dios231
    Jul 12, 2016 at 12:17
  • Where does the dynamic text should come from? The database? Should it be calculated at once (current date, some URL)? Jul 13, 2016 at 7:41
  • Yes, dynamic text should come from database. Jul 16, 2016 at 9:51

1 Answer 1

2

The addHelpButton() method has the parameter $component that contains the current text to be shown when clicking onto the help icon (Help icon). This text is read from the $string array defined in the language file.

The trick here is that the array element can be built dynamically:-)

Let's make an example: In your mod_form.php you build your help icon with:

$mform->addHelpButton ( 'element_name', 'your_identifier', 'your_help_text' );

The text your_help_text is read in your language file usually with:

$string ['your_help_text_help'] = 'This is my static help text';

Here you change this line with:

$string ['your_help_text_help'] = get_dynamic_help_string($any_parameter);

And then you define your function:

function get_dynamic_help_string($any_parameter) {
$text = This is my dynamic help text with the current date: ;
$text .= ' '.date("Y/m/d");
return $text; }

Now, any time you refresh the form, the help text will be built dynamically. Of course, you can use any logic here, if you want.

Note: you need here to manage the cache of your plugin in order to always get the newest result of your function. Please, refer to this link for deleting the Moodle cache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.