Custom theme function with drupal render I'm trying to make a custom module based on menu module to render a sitemap.

I want to use a custom theme function for rendering it but for unknown reasons my variables are not passed to the theme function. Here is my code (simplified so we get what matter) :

function custom_module_theme() {
  return array(
    'custom_module_link' =&gt; array(
      'variables' =&gt; array(
       'attributes' =&gt; NULL,
       'title' =&gt; NULL,
       'href' =&gt; NULL,
       'below' =&gt; NULL,
       'original_link' =&gt; NULL,
      ),
    ),
  );
}

function theme_custom_module_link(array $variables) {
 $element = $variables;
 $output = ...;
 ...
  return '&lt;li' . drupal_attributes($element['#attributes']) . '&gt;' . $output . "&lt;/li&gt;\n";
}

function _custom_module_tree_output($tree) {
    ...
    ...
    // Allow menu-specific theme overrides.
    $element['#theme'] = 'custom_module_link';
    $element['#attributes']['class'] = $class;
    $element['#title'] = $data['link']['link_title'];
    $element['#href'] = $data['link']['link_path'];
    $element['#original_link'] = $data['link'];
  }
 return $element;
}

function custom_module_page() {
  $tree = ...
  $output = _custom_module_tree_output($tree);

  return drupal_render($output);
}


This code return a error page with the following : TypeError: Argument 1 passed to drupal_attributes() must be of the type array, null given ...

I don't understand why drupal_render doesn't iterate over the $element['#theme'] call to fetch variables as described in the documentation. What I'm missing ?


  From the doc : Basically, the '#theme' = 'function_name' calls
  theme_function_name(), and other array values of the form '#var_name'
  = $value in the same array are passed as arguments to the theme function


If I dpm $variables in my theme_custom_module_link function, variables are set as NULL as in my hook_theme ...
What I wanted to do is to get the html through a function and not a template. So actually there is no need to set the variables, just the 'render element' did the trick.

function custom_module_theme() {
  return array(
    'custom_module_link' =&gt; array(
      'render element' =&gt; 'element',
    ),
  );
}