Use template conditionally in drupal

In Drupal you want to use some other template on the basis on some condition. This blog is all about of using template on the basis of some condition. Write the following function in your theme’s template.php and replace THEME with your theme name.

This preprocess hook load the tpl with name somename–test.tpl.php when content type is page.

function THEME_preprocess_page(&$variables) {
  if ($variables['node']->type == 'page') {
   // If the content type's machine name is "page" the file
   // name will be "somename--test.tpl.php".
   $variables['theme_hook_suggestions'][] = 'somename--test';