1

The project I'm working on has a specific requirement where I need to export the main menu as an HTML file. I figured the simplest way to do it would be using views but I found that views doesn't interact with the menu system.

I looked up the menu_import module to see how it exports menus to JSON files to see if I could rewrite the output to be HTML but haven't really gotten too far with that.

Any ideas how I can approach this?

3 Answers 3

2

Use the next code:

$tree = menu_tree_all_data('main-menu');
$menu_html = render(menu_tree_output($tree));
file_put_contents('myfile.txt', $menu_html);

Source: Programmatically load a menu.

EDIT If you want to make it downloadable you can add next code to your page or submit callback:

// Get menu tree.
$tree = menu_tree_all_data('main-menu');
$menu_html = render(menu_tree_output($tree));

// Download menu txt file.
$filename = "menu.txt";
drupal_add_http_header('Content-Type', 'text/plain; charset=utf-8');
drupal_add_http_header('Content-Disposition', 'attachment; filename="' . $filename . '"');
drupal_send_headers();
echo $menu_html;
drupal_exit();
1
  • If you want to automate this, wrap above code in a function and call it from hook_menu_link_insert (), *_update() and *_delete(). As soon as you add a link or edit the menu the file will update. Jan 6, 2015 at 9:41
0

It really depends on how you made the menu. If it is coded in the template.php, you need to copy the coding from the template.php If it is made by some kind of module, you need to copy the html codes, js codes and css codes from module folder. Or maybe you just need to duplicate that block and show it on the page you want.

Or you can use , you can add css {display: none} to all other parts. and add the iframe like

To make it to be a html format, you just need to add tag.

-1

XML Sitemap module or Sitemap module

Using the XML sitemap module would allows you to generate your content and/or your data on XML file that you can manipulate on a different end.

Sitemap Module would help you to generate a list of all your items on your menu on a Drupal page.

1
  • Thanks. XML Sitemap doesn't allow me to select a specific menu and Sitemap generates a node, which I can do as well. Jan 5, 2015 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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