Creating a page Menu in sidebar

Dear members,

created a plugin which will show a page with some tabs. I want to add a page menu to the side bar and clicking on that menu i want to load a new page with some other tabs...

what changes should be made in page handler ($page){

 

}

thank you

  • Here is my code

        elgg_register_page_handler('Aathira','Aathira_page_handler');

    function Aathira_page_handler($page) {
        $base = elgg_get_plugins_path() . 'Aathira/pages/Aathira/';

        if (!isset($page[0])) {
            $page[0] = 'vision';
        }

        $vars = array();
        $vars['page'] = $page[0];


    require_once "$base/index.php";

    return true;
    }

    This is the index.php file


    elgg_push_breadcrumb(elgg_echo("Aathira:wwr"), "Aathira/");

    switch ($vars['page']) {
        case 'vision':
        default:
            $content = elgg_view('tabs/vision');
                    elgg_push_breadcrumb(elgg_echo("Aathira:vision"));
            break;
        case 'people':
            gatekeeper();
            $content = elgg_view('tabs/people');    
                    elgg_push_breadcrumb(elgg_echo("Aathira:people"));    
                    break;
        case 'functions':
            $content = elgg_view('tabs/functions');
                    elgg_push_breadcrumb(elgg_echo("Aathira:functions"));
            break;
            case 'supporters':
                    $options = array(
                    'types' => 'object',
                    'subtypes' => 'market',
                    'limit' => 10,
                    'full_view' => false,
                    'pagination' => true,
                    'view_type_toggle' => false,
                    'metadata_name' => "marketcategory",
                    'metadata_value' => 'SupportersAds',
                    //'metadata_value' => array('SupportersAds','LinuxOS'),
                    );
                    $content = elgg_list_entities_from_metadata($options);
                    elgg_push_breadcrumb(elgg_echo("Aathira:supporters"));
            break;
            case 'helpus':
            $content = elgg_view('tabs/helpus');
                    elgg_push_breadcrumb(elgg_echo("Aathira:helpus"));
            break;
            case 'LinuxOS':
            $options = array(
                    'types' => 'object',
                    'subtypes' => 'market',
                    'limit' => 10,
                    'full_view' => false,
                    'pagination' => true,
                    'view_type_toggle' => false,
                    'metadata_name' => "marketcategory",
                    'metadata_value' => array('LinuxOS'),
                    );
                    $content = elgg_list_entities_from_metadata($options);
                    elgg_push_breadcrumb(elgg_echo("Aathira:LinuxOS"));
            break;
    }



    $title = elgg_echo("Aathira:wwr");
        
    $body = elgg_view_layout('content', array(
        'content' => $content,
            'sidebar' => elgg_view('Aathira/sidebar'),
        'title' => $title,
        'filter_override' => elgg_view('Aathira/nav', array('selected' => $vars['page'])),
        
    ));

    echo elgg_view_page($title, $body);
    ?>

    and this is my filter overriding file

    $tabs = array(
        'vision' => array(
            'title' => elgg_echo('Aathira:vision'),
            'url' => "Aathira/vision",
            'selected' => $vars['selected'] == 'vision',
        ),
        'people' => array(
            'title' => elgg_echo('Aathira:people'),
            'url' => "Aathira/people",
            'selected' => $vars['selected'] == 'people',
        ),
            'supporters' => array(
            'title' => elgg_echo('Aathira:supporters'),
            'url' => "Aathira/supporters",
            'selected' => $vars['selected'] == 'supporters',
        ),
        'functions' => array(
            'title' => elgg_echo('Aathira:functions'),
            'url' => "Aathira/functions",
            'selected' => $vars['selected'] == 'functions',
        ),
            'helpus' => array(
            'title' => elgg_echo('Aathira:helpus'),
            'url' => "Aathira/helpus",
            'selected' => $vars['selected'] == 'helpus',
        ),
            'LinuxOS' => array(
            'title' => elgg_echo('Aathira:LinuxOS'),
            'url' => "Aathira/LinuxOS",
            'selected' => $vars['selected'] == 'LinuxOS',
        ),

    );

    echo elgg_view('navigation/tabs', array('tabs' => $tabs));

    I want to create a page menu in the side bar... on clicking that it should load a new page with some other tabs.. hows it possible?

  • before
    $body = elgg_view_layout('content', array(
        'content' => $content,
    extend viz --
    $content.=$MySideBarPageMenu; // 7 have css to control MySideBarPageMenu's layout.

     

  • what about adding $vars['page'] = $page[0]; and so on ..?

  • @Satheesh PM I am sorry maybe I am not helpful but I have one thing in my mind now. I would like to keep my all menu buttons from my elgg default theme to the very left side of the main home page. And I wanna remove the complete menu from the header of my elgg default theme.

    You are asking the same thing? I would like to have that, all menu instead of in header wanna show in the very left side and if they are sicky that would be more great.

    Awaiting for your kind suggestion/ response.

    Cheers

  • I've got it working to have a page with custom tabs (among other pages used by this plugin) and a sidebar with links (to this page and the others).

    The pagehandler in start.php looks like this for the page with custom links:

    function tidypics_page_handler($page) {

        if (!isset($page[0])) {
            return false;
        }

        elgg_load_js('tidypics');
        
        $base = elgg_get_plugins_path() . 'tidypics/pages/photos';
        $base_lists = elgg_get_plugins_path() . 'tidypics/pages/lists';
        switch ($page[0]) {

                    case "mostrecentall":
                            require "$base_lists/mostrecentimagesall.php";
                            break;

                    case "mostrecentowner":
                            require "$base_lists/mostrecentimagesowner.php";
                            break;

                    case "mostrecentfriends":
                            require "$base_lists/mostrecentimagesfriends.php";
                            break;
            default:
                return false;
        }

        return true;
    }

    Then I have the pages files that build up the custom tab page (tidypics/pages/lists/mostrecentimagesall.php, tidypics/pages/lists/mostrecentimagesowner.php and tidypics/pages/lists/mostrecentimagesfriends.php). For example in mostrecentimagesall.php the page is getting displayed with this code (of course you need to populate $area2 and $title with the desired content before):

    $body = elgg_view_layout('content', array(
            'filter_override' => elgg_view('filter_override/mostrecent', array('selected' => 'all')),
            'content' => $area2,
            'title' => $title,
            'sidebar' => elgg_view('photos/sidebar', array('page' => 'all')),
    ));

    // Draw it
    echo elgg_view_page($title, $body);

    In 'filter_override' the 'selected' => 'all' is the identifier of the tab (more about that below). The sidebar gets created by the view tidypics/views/default/photos/sidebar.php. The 'page' => 'all' is an identifier that can be used in the sidebar view to populate the sidebar depending on the specific page.

    Filter override is in tidypics/views/default/photos/filter_override/mostrecent.php:

    <?php

    $base = elgg_get_site_url() . 'photos/';

    $tabs = array(
        'all' => array(
            'title' => elgg_echo('all'),
            'url' => $base . 'mostrecentall',
            'selected' => $vars['selected'] == 'all',
        ),
        'mine' => array(
            'title' => elgg_echo('mine'),
            'url' => $base . 'mostrecentowner',
            'selected' => $vars['selected'] == 'mine',
        ),
        'friends' => array(
            'title' => elgg_echo('friends'),
            'url' => $base . 'mostrecentfriends',
            'selected' => $vars['selected'] == 'friends',
        )
    );

    echo elgg_view('navigation/tabs', array('tabs' => $tabs));

    Here you see which pages should be behind the tab links. The url is resolved with the pagehandler. The $vars['selected'] variable is populated by the elgg_view call of the 'filter_override' attribute.

    The sidebar menu is created in the tidypics/views/default/photos/sidebar.php view:

    <?php
    /**
     * Sidebar view
     */

    $current_user_guid = elgg_get_logged_in_user_guid();

    $base = elgg_get_site_url() . 'photos/';

    elgg_register_menu_item('page', array('name' => 'A10_tiypics_mostrecent',
                                          'text' => elgg_echo('tidypics:mostrecent'),
                                          'href' => $base . 'mostrecentall',
                                          'section' => 'A'));
    elgg_register_menu_item('page', array('name' => 'A20_tiypics_albums',
                                          'text' => elgg_echo('tidypics:albums'),
                                          'href' => $base . 'all',
                                          'section' => 'A'));

    $page = elgg_extract('page', $vars);
    $image = elgg_extract('image', $vars);
    if ($page == 'upload') {
            if (elgg_get_plugin_setting('quota', 'tidypics')) {
                    echo elgg_view('photos/sidebar/quota', $vars);
            }
    } else {

    ....

    The menu items are created with elgg_register_menu_item(). The href is again resolved with the pagehandler. The 'name' should be something unique. As the sorting of the menu items is done by name by default you can define the order of the menu items in the sidebar also by giving suitable names to the menu items (A10_ before A20).

    You also see

    $page = elgg_extract('page', $vars);

    Here the value of 'page' is extracted. This value is set when calling the sidebar view in the elgg_view_layout() call in tidypics/views/default/photos/filter_override/mostrecent.php. What you see in sidebar.php is that I define two sidebar menu items that get displayed on all pages (within the tidypics context). The if-clause

    if ($page == 'upload') {

    will display the following content of the sidebar only when called by

    'sidebar' => elgg_view('photos/sidebar', array('page' => 'upload')

    In case of the upload sidebar items these are included from another view (photos/sidebar/quota) respectively.


    I hope you can follow my explanation how you could build up a custom page with tabs including sidebar menu items. I'm not ready yet to upload a tidypics version where I've implemented such a page. Hopefully, I can publish at least a version on github soon. Then you could also see the implementation "live".

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking