2
votes

I am developing a module and I need to call different .tpl.php layouts from the theme directory per page.So what I currently have is:

 return theme('adverts_index', array('adverts' => $advertsThemeArray));    

That is what I return in one of the page callback functions. Now this works perfectly without a problem but in another page callback function within the module I attempt the same thing with a different theme hook but it does not call the layout specified by the theme hook.

 $r = theme('adverts_view_advert', array(
      'advert' => array(
        'id' => $advert->aid,
        'seller' => $advertiser,
        'more_from_user' => array(),
        'year' => $advert->year,
        'condition' => $advert->condition,
        'region' => $advert->region,
        'city' => $advert->city,
        'content' => $advert->description,
        'bids' => $allBidsArray,
      ),
    )
  );
  return $r;

The page is not complete blank, the main page.tpl.php which is used on every page which contains the header and what not does still display. Just the template I am trying to call to its contents is not displaying.

This is my hook_theme:

 function adverts_theme() {
  $theme = array();
  $theme['adverts_index'] = array(
      'template' => 'adverts-index',
      'variables' => array(
          'advert' => array(
            'title' => null,
            'formatted_price' => null,
            'image' => null,
            'permalink' => null,
            'formatted_date' => null,
            'description' => null,
          ),
        ),
    );

  $theme['adverts_view_advert'] = array(
      'template' => 'adverts-single',
      'variables' => array(
          'advert' => array(
                'id' => null,
                'seller' => null,
                'more_from_user' => null,
                'year' => null,
                'condition' => null,
                'region' => null,
                'city' => null,
                'content' => null,
                'bids' => null,
            ),
          ),
        );
  return $theme;

}

Any help would be highly appreciated!

1

1 Answers

2
votes

arguments changed to variables in Drupal 7, and since either variables or render element is required the registry won't be picking up your theme.

Make the two changes in the hook_theme() implementation, clear the caches, and you should be good to go.