One HTML file for multiple ionic versions

One HTML file for multiple ionic versions

על ידי Marcus Green בתאריך
מספר תגובות: 1
תמונה של Core developers תמונה של Particularly helpful Moodlers תמונה של Plugin developers תמונה של Testers

This page

https://docs.moodle.org/dev/Adapt_your_Mobile_plugins_to_Ionic_5#Supporting_both_Ionic_3_and_Ionic_5

Has text that says

"You can also have a single file with different HTML depending on the appversioncode, that’s up to you."

How can that be done?

The choice group code is like this

public static function mobile_init($args) {
    global $CFG;

    $args = (object) $args;

    $foldername = $args->appversioncode >= 3950 ? 'latest' : 'ionic3';

    return [
        'templates' => [],
        'javascript' => file_get_contents($CFG->dirroot . "/mod/choicegroup/mobile/js/$foldername/init.js"),
    ];
}
https://github.com/dpalou/moodle-mod_choicegroup/blob/2bfb0872e070966bf8ff640f6d5a8255dbb3b583/classes/output/mobile.php#L47

Which would translate to this in my question type
https://github.com/marcusgreen/moodle-qtype_gapfill/blob/master/classes/output/mobile.php
In the spirit of social constructivism, me explaining it here has given me a clue as to where I ought to look next, but if anyone can
shortcut my next step that would be great.

ממוצע דרוגים:Useful (1)
בתגובה ל: Marcus Green

Re: One HTML file for multiple ionic versions

על ידי Dani Palou בתאריך
תמונה של Core developers תמונה של Moodle HQ תמונה של Particularly helpful Moodlers תמונה של Peer reviewers תמונה של Plugin developers

Hi Marcus!

in the PHP function, to return the template with data you need to call $OUTPUT->render_from_template and pass the data needed by the template. You could do something like:

$data = [
    'isionic5' => $args->appversioncode >= 3950,
];

...

'html' => $OUTPUT->render_from_template('TEMPLATE_PATH', $data),

Then in the template you can use that variable to render one content or another, e.g.

<%^ isionic5 %>
    <!-- Ionic 3 HTML in here. -->
<%/ isionic5 %>
<%# isionic5 %>
    <!-- Ionic 5 HTML in here. -->
<%/ isionic5 %>

However, you cannot do that for Javascript files, in that case it's better to have different files like you did.

Cheers,

Dani