Moodle Block Development Question

Moodle Block Development Question

by Dalin Williams -
Number of replies: 2

Hello All,

My question is one that may be quite silly, but I feel the need to address it anyways. As per my Previous Question, I am relativity new to moodle development, and am seeking advice as I continue my quest to develop a functional purpose.

Say I have a block, and from said block I want to create a link to a new page within moodle. As far as I could tell from reading the API and both block tutorials, the method to use would be via the use of the navigation, page, and output APIs. However, when browsing through the plugins catalog, I noticed that several plugins that facilitate this action do not use this API, they use php-embedded HTML and JavaScript. My question is which is the correct method, as well as any other tips one could give a new-comer to the moodle dev practice. Thank you in advance.

Average of ratings: -
In reply to Dalin Williams

Re: Moodle Block Development Question

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I'm not quite clear what you are asking for, maybe you could explain it better?

When you say a 'new page', do you mean a user created page (e.g. you click 'new page', then enter some details and that page is created) or simply a functional page that is part of your plugin (e.g. the block has a link that says 'view report' and when you click on it it shows the contents of a new report defined within your plugin).

If it is a new functional page, then you should create a PHP file within your plugin, then (preferably) use the following function to link to it:

$url = new moodle_url('/blocks/myblock/mypage.php', array('param' => 'value'));
$content->text .= html_writer::link($url, get_string('nameoflink', 'block_myblock');

Within mypage.php, you will want to use require_login([$course], [$autologin], [$cm]) function to set up the page context (and make sure the user is logged in) the $PAGE object to set the title, etc, possibly use $PAGE->navbar to add some custom elements to the navbar and then use the $OUTPUT object to generate parts of the page content (see almost any script in Moodle for more details).

Average of ratings: Useful (1)