Customizing the front page

Hi there. I am trying to follow the instructions at

Customizing the front page

 

to create my own front page. I used this code for start.php

<?php

function pluginname_init() {
    // Replace the default index page
    elgg_register_plugin_hook_handler('index', 'system', 'new_index');
}

function new_index() {
    if (!include_once(dirname(dirname(__FILE__)) . "/pluginname/pages/index.php"))
        return false;

    return true;
}

// register for the init, system event when our plugin start.php is loaded
elgg_register_event_handler('init', 'system', 'pluginname_init');
?>

But I keep receiving the Fatal Error page. Any hints?.

Thanks.

 

 

  • I guess you got the info from http://learn.elgg.org/en/stable/guides/themes.html#customizing-the-front-page. Unfortunately, this info is no longer correct (it was for older versions of Elgg but it's no longer working this way on any recent version of Elgg).

    Most likely the simpliest way is described at http://learn.elgg.org/en/stable/tutorials/indexpage.html. So, follow the instructions for overriding views (http://learn.elgg.org/en/stable/guides/views.html#altering-views-via-plugins) and you would only need to place your modified index.php in mod/YOUR_PLUGIN/views/default/resources/index.php. Apart from that you only need a manifest.xml and a start.php (<?php in the first line is all that needs to be in start.php at a minimum).

    The other way that still works is with

    elgg_register_page_handler('','my_index');

    in the init function of your plugin and the function

    function my_index() {
    
        if (!include_once(dirname(__FILE__) . "/index.php")) {
            return false;
        }
    
        // return true to signify that we have handled the front page
        return true;
    }

    also in start.php. The path used in include_once might have to be adjusted depending on where you placed your index.php.

  • Thank you iionly

    I tried both ways:

    1.- With an empty start.php

    --

    <?php

    --

    and mod/MYPLUGIN/views/default/resources/index.php

    --

    <?php

    $params = array(
        'title' => 'Hello world!',
        'content' => 'My first page!',
        'filter' => '',
    );

    $body = elgg_view_layout('content', $params);

    echo elgg_view_page('Hello', $body);

    --

    and then

    2.- with start.php

    --

    <?php
    // usual stuff
    elgg_register_event_handler('init', 'system', 'indice2_init');

    // plugin init function
    function indice2_init() {
      // Replace the default index page
      // elgg_register_plugin_hook_handler('index', 'system', 'new_index');
      elgg_register_page_handler('','my_index');
    }

    function my_index() {

        if (!include_once(dirname(__FILE__) . "/pages/index.php")) {
            return false;
        }

        // return true to signify that we have handled the front page
        return true;
    }

    --

    and mod/MYPLUGIN/pages/index.php with just the content as before.

    Both produce an identical output as far as I can see. I then went back to the original start.php code in http://learn.elgg.org/en/stable/guides/themes.html#customizing-the-front-page

    --

    <?php
    
    function pluginname_init() {
        // Replace the default index page
        elgg_register_plugin_hook_handler('index', 'system', 'new_index');
    }
    
    function new_index() {
        if (!include_once(dirname(dirname(__FILE__)) . "/pluginname/pages/index.php"))
            return false;
    
        return true;
    }
    
    // register for the init, system event when our plugin start.php is loaded
    elgg_register_event_handler('init', 'system', 'pluginname_init');
    ?>

    --

    and, again, it all went well. The original error must have been in my index.php.

    Thank you for your lead.