0

I'm trying to create a one-pager website in which I'd like to get all the main-menu links and load their complete content underneath each other on the homepage. So that's blocks, display etc. in all.

So I was thinking I could just get the page and render it in an each link; but I can't figure out how I can load and render multiple pages in one go.

I make a preprocess_page hook and got the menu links I want. How do I go about and get all those pages underneath each other now?

function myproject_preprocess_page (&$vars) {

    //Get ALL The pages from the main menu and ALL the content
    //And make one large content for all of it to create a one-pager
    if (isset($vars['node']) && strtolower($vars['node']->title) == "home") {
        $menu = menu_tree_all_data('main-menu');
        if ($menu) {
            foreach ($menu as $menuItem) {
                $a = menu_get_item($menuItem['mlid']);
                //echo render ($a); // Gives nothing
                //echo drupal_render_page($a); //time-out
            }

        }


}

}

I also tried with menu_load_links but I can't really see if I'm extracting the node now and how to render that.

$menu = menu_load_links('main-menu');

if ($menu) {
    foreach ($menu as $item) {
        $b = menu_get_item($item['link_path']);
    }
}
1

you cannot render menu entries, but render arrays. you need to get the node from the menu item's path (see here) and then you can use node_view to get its render array.

a way better solution would be to make a views page, with a menu_node relationship.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.