Using the coursepagemethod option of CoreCourseModuleDelegate correctly

Using the coursepagemethod option of CoreCourseModuleDelegate correctly

by Neill Magill -
Number of replies: 2
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

I have been trying to have a play with the coursepagemethod option in the a  CoreCourseModuleDelegate

The documentation suggests that it should be a method that returns html (I assumed it should be the content that you wish to be displayed) however there is documentation that suggests it should be a template

Inside db/mobile.php I assumed that if I added something like:

'coursepagemethod' => 'inline',

it would require me to add a method that was classes/output/mobile.php accepting similar parameters to something declared via method (except that it returned a string)

public static function inline(array $args) : string {
    return '<p>STUFF came from here!</p>';
}

This did not seem to work, nor did something like:

    public static function inline(array $args) : array {
        return array(
            'templates' => array(
                array(
                    'id' => 'main',
                    'html' => '<p>STUFF came from here!</p>',
                ),
            ),
            'javascript' => '',
            'otherdata' => [],
            'files' => [],
        );
    }

Should I be defining the method somewhere else? Should it have a different method signature?

Average of ratings: Useful (1)
In reply to Neill Magill

Re: Using the coursepagemethod option of CoreCourseModuleDelegate correctly

by Anthony Durif -
Picture of Plugin developers
Hello,

I did a similar development for one of my plugin.
But I did not use html directly and I used a template like it was suggested in the documentation.

Did you try or did you have the same behaviour using a template:
  
'html' => $OUTPUT->render_from_template('mod_myplugin/mobile_view')
And then just put your html code in the template ?
In reply to Anthony Durif

Re: Using the coursepagemethod option of CoreCourseModuleDelegate correctly

by Neill Magill -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
I did indeed use a template for my real code, I was simplifying thigs for the example (by showing the hypothetical output of a template call).