Load a static custom landing page by default and link it to Moodle

Load a static custom landing page by default and link it to Moodle

by Vladislav Kamynin -
Number of replies: 4

I would like to create a landing page, just like I normally would, without using Moodle at all, so that it doesn't use any Moodle blocks or headers/footers.. Just like a separate page with my own HTML, CSS, Javascript/jQuery animations.. and then make it load by default instead of whatever Moodle does by default. So, the first question is:

1. Where do I set the server default page? Do I need to edit the htaccess file? The line 'DirectoryIndex index.php index.html index.htm'? Do I just replace it with the filename of my static page? Or do I delete the files index.php and index.htm and replace the index.html with my own page? What do I do so that I don't damage Moodle in any way? 

And the second question is.. 

2. I need that landing page to lead the users to Moodle. Maybe I just provide a link to the login page or something. Or maybe if the user is loged-in already it will just lead him to the Moodle default page (not the landing page), with all the blocks, courses, etc. What should I do about that?

Help me out. I want to create a nice landing page with cool JS effects... So that this is the first thing that users see. And then they click on the link and get the login form or the actual Moodle website if it is in the cookies.

Average of ratings: -
In reply to Vladislav Kamynin

Re: Load a static custom landing page by default and link it to Moodle

by Justin Hunt -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

One way to approach is to set an alternate login url, and require users to be logged in. Then un authenticated users will be forwarded to your alternate login page.

You can set that at:

site admin -> plugins ->authentication ->manage authentication -> alternate login URL

But there wouldn't be any harm in setting index.html as your default page in .htaccess . This page  looks helpful 

You could alter index.php, but the danger is that when upgrading Moodle you might overwrite your customized file. So that would not be the best option.

In reply to Vladislav Kamynin

Re: Load a static custom landing page by default and link it to Moodle

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

There are many ways to implement the custom front page. I personally tried two of them. The first one used the $CFG->customfrontpageinclude. It worked well for me to have it implemented via a local plugin (say local_frontpage) and use that directive to include it instead of the default index.php contents.

The other option, that we currently use at moodle.org community portals, implements the custom front page via a theme. The theme allows you to assign a layout file that will be used for the site front page.

Average of ratings: Useful (2)
In reply to David Mudrák

Re: Load a static custom landing page by default and link it to Moodle

by Sandeep B -

Mr.David mudrak, Can you please eloborate the first way you suggested " The first one used the $CFG->customfrontpageinclude. It worked well for me to have it implemented via a local plugin (say local_frontpage) and use that directive to include it instead of the default index.php contents." in step wise or any external link which can explain the process of loading a static custom landing page can be helpful for me. TIA

In reply to David Mudrák

Re: Load a static custom landing page by default and link it to Moodle

by Russell England -
Picture of Plugin developers

Works well for me, thank you for the tip!

Just one little thing, the header has already been printed so I added this little bit of code


Add this to config.php

$CFG->customfrontpageinclude = 'local/plugin/index.php'; // No leading slash.

 Then in local/plugin/index.php

<?php
 
...
 
// Add this to your page setup.
if ($PAGE->state <= moodle_page::STATE_PRINTING_HEADER) {
    // If calling from the front page then it already has a header so don't print it.
    // Otherwise print as normal,
    echo $OUTPUT->header();
}
 
...
 
echo $OUTPUT->footer();
 
// Add this to the end of the page.
exit(); // This forces the frontpage to stop at this point so nothing else is printed.