简体   繁体   中英

How to create dynamic link button in moodle

I want to create a button in moodle which redirects the user to the next topic so the topic's URL can change according to activity.

I don't know to do it I have tried using the below code.

 $output .= html_writer::div("<a class='mod_quiz-next-nav' href='$url'>Goto Next Session</a>");
        // redirect('https://web.whatsapp.com/');
        $output .= html_writer::link($url, get_string('finishreview', 'quiz'),
                array('class' => 'mod_quiz-next-nav'));
        return $output;

please suggest to me how to set a button which URL can change dynamically.

A simple solution would be

global $OUTPUT;

...

$params = array('something' => 'something');

$url = new \moodle_url('/myurl/something.php', $params);

$button = $OUTPUT->single_button($url, get_string('finishreview', 'quiz'), 'get',
    array('class' => 'mod_quiz-next-nav');

$output = \html_writer::div($button, 'mod_quiz-next-nav');

A more complex and better solution would be to add the code to a renderer class. But that will take longer to explain.

See here for details

https://docs.moodle.org/dev/Renderer_best_practices

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM