How to add a new page? I tried to add a new page index.php in \admin\tool\demo. Here's the code: (from https://docs.moodle.org/dev/Output_API)
<?phpAnd it returned 'Access denied'. What do I need to do to access this page?
// Standard GPL and phpdocs
require_once(__DIR__ . '/../../../config.php');
// Set up the page.
$title = get_string('pluginname', 'tool_demo');
$pagetitle = $title;
$url = new moodle_url("/admin/tool/demo/index.php");
$output = $PAGE->get_renderer('tool_demo');
$renderable = new \tool_demo\output\index_page('Some text');
This may be simple, but I just learned moodle. Thank you for your advice.
As for the 'Access denied', make sure you are logged in as a site administrator on your Moodle site since the page you are creating is an Admin tool.
If that is the only file you have in /admin/tool/demo/, then you are going to get a bunch of errors. For that example to work, you would need to write a renderer for your plugin and create a mustache template (explained further down on the page you linked). Once you have those set up, then you will be able to see some output.
If you just want to create a simple one file page to get started before learning more about admin tools and plugin development, here is some code to create a one-page local plugin:
<?php // Standard config file and local library. require_once(__DIR__ . '/../../config.php'); // Setting up the page. $PAGE->set_context(context_system::instance()); $PAGE->set_pagelayout('standard'); $PAGE->set_heading("Demo"); $PAGE->set_url(new moodle_url('/local/demo/index.php')); // Ouput the page header. echo $OUTPUT->header(); // Output your custom HTML. // In the future, read about templates and renderers so you don't have to echo HTML like this. echo '<p>Test paragraph!</p>'; // Output the page footer. echo $OUTPUT->footer();
Place the above in an index.php file in /local/demo/. Then visit http//YOUR_MOODLE_SITE/local/demo/index.php.
Also, if you are just looking to add a static page. Ex: you just want to create a simple HTML page describing something, and don't require a complex plugin (like above). Just go to your site front page with editing on, and click 'Add an activity or resource' then add a 'Page'. You will be able to set a title and page content.
Then you can access this page from the side bar under "Site pages". Or you can copy the link to the page and link to it from anywhere.