Theme template.php functions after bootstrap I'm trying to print a drupal menu outside drupal. In order to achieve this I ran the bootstrap as follows:

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);


And I render my menu as follows:

public static function getDrupalMenu($menuName) {
        $menu_output = &amp;drupal_static(__FUNCTION__, array());

        if (!isset($menu_output[$menuName])) {
        $tree = menu_tree_all_data($menuName);
        $menu_output[$menuName] = menu_tree_output($tree);
        }
        return render($menu_output[$menuName]);
    }


Which is basically just a copy of the menu_tree function AND with menu_tree_all_data instead of menu_tree_page_data so I get all links no matter what page I'm on.

Everything works fine so far, my menu is printed, everybody is happy... but unfortunately my links are incorrect somehow. To solve this I've used a solution for absolute links as described here:

How to force absolute links on a menu tree in Drupal 7

So I use:

function mythemename_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  $output = l($element['#title'], $element['#href'], array_merge($element['#localized_options'], array('absolute' =&gt; TRUE)));
  return '&lt;li' . drupal_attributes($element['#attributes']) . '&gt;' . $output . $sub_menu . "&lt;/li&gt;\n";
}


This works fine on my drupal site, but where I call the getDrupalMenu() after initializing the bootstrap it does not work (empty result, not even the original one). I probably have to set the theme or something, but I can't find what or where to do so. 

Just to be clear: when I change the code in core (menu.inc) is works fine on both sites... it just gives en empty result when I override it in the theme.

Any pointers or solutions ?
While what you are doing could work, this is not what you want to do. If you want to render your menus outside Drupal you should do it a more  robust way to implement this using Drupal best practice etc.

One way would be to


create a public URL that returns the menus. This could return just the data or markup. 
Have you custom code consume the API, so you fetch the data via http instead of manually trying to bootstrap Drupal.


You also need to ask yourself why this custom code lives outside Drupal. If you can bootstrap Drupal etc, the code might as well be part of Drupal via a module.

Boostrapping Drupal yourself is possible but a lot of crazy bugs can show up. Drupal depend on a lot of various stuff like $_GET / $_POST and other stuff that you might forget to handle. Also if you update Drupal this code can easily break as you are using internal functions which can change in various ways.