Trouble theming Ubercart's cart page (Drupal 7) using hook_theme Ubercart's uc_cart module offers a 'cart' page which I'm willing to have a theme/template. What I did is added following in mymodule_theme():

    'uc_cart_view' =&gt; array(
        'render element' =&gt; 'page', // IS THIS CORRECT?
        'template' =&gt; 'cart', // Located in mymodule/templates/cart.tpl.php
        'path' =&gt; drupal_get_path('module', 'mymodule') . '/templates', 
    ),


But No luck! 

My Question:

Shall I have some other value for render element key? Or shall I have a variables entry? I tried with variables with an empty array instead of render element entry but no luck.

Here goes some more information about Ubercart's uc_cart module so that you can help me solving this issue:

For Your Consideration

Portion from uc_cart_menu:

$items['cart'] = array(
    'title' =&gt; 'Shopping cart',
    'description' =&gt; 'View/modify the contents of your shopping cart or proceed to checkout.',
    'page callback' =&gt; 'uc_cart_view',
    'access arguments' =&gt; array('access content'),
    'file' =&gt; 'uc_cart.pages.inc',
  );


So I figured out I should use my custom template for uc_cart_view. This uc_cart_view() is a function in *uc_cart.pages.inc* page, I've pasted the function here for your convenience.

Any help on what I'm doing wrong?
uc_cart_view() is not a form builder; it is a page callback. As such, theme_uc_cart_view() is not automatically called for uc_cart_view(). It is the page callback that needs to call the necessary theme function, or refer it such as in the following code.

  if (empty($items)) {
    return array(
      '#theme' =&gt; 'uc_empty_cart',
    );
  }


What you can do is the following:


Implement hook_menu_alter() to alter the page callback invoked for http://example.com/cart.

function mymodule_menu_alter(&amp;$items) {
  if (isset($items['cart'])) {
    $items['cart']['page callback'] = 'mymodule_cart_view';
  }
}

Implement the page callback to output the content as you want it to be.


I cannot suggest the code to write for mymodule_cart_view(). Looking at the code used from uc_cart_view(), I notice the main part is the following one.

  // Load the array of shopping cart items.
  $items = uc_cart_get_contents();

  // Display the empty cart page if there are no items in the cart.
  if (empty($items)) {
    return array(
      '#theme' =&gt; 'uc_empty_cart',
    );
  }

  $build = array();
  // Load through the cart panes...
  foreach (uc_cart_cart_pane_list($items) as $id =&gt; $pane) {
    // If the pane is enabled...
    if ($pane['enabled']) {
      // Add its output to the cart view.
      $build[$id] = $pane['body'];
    }
  }


What a page callback can return, in Drupal 7 is:


a string containing the markup to output
an array accepted from drupal_render(), such as the following ones

$build = array(
  '#theme' =&gt; 'node', 
  '#node' =&gt; $node, 
  '#view_mode' =&gt; $view_mode, 
  '#language' =&gt; $langcode,
);




$block = array(
  '#markup' =&gt; '&lt;em&gt;' . t('There are no rows matching the selected criteria') . '&lt;/em&gt;'.
);




$styles = array(
  '#type' =&gt; 'styles', 
  '#items' =&gt; $css,
);



As side note, in your theme definition, the template filename cannot be "cart"; as the template file is for "uc_cart_view" you can report it to be "uc_cart_view" or "uc-cart-view." Any other filenames are not accepted, from Drupal.