2

I have a special part of my site that needs a very different kind of layout from the rest of my site. I have created a template file called page--special.tpl.php that implements the kinds of themeing I need. This page works fine as the long as the page that is being viewed is at the endpoint ?q=special but I do not want to have to make a different template for each page in this special section (all of which would have the same theme code). Is there anyway to have all pages that have endpoints starting with ?q=special use this template?

Is there some other better way to do this?

2

If the pages www.yoursite.com/special, www.yoursite.com/special/anotherpage, etc are the actual paths to the content and not aliases, then page--special.tpl.php should work for all of them. If, however, they are aliases to node content, eg, www.yoursite.com/special/anotherpage is really something like www.yoursite.com/node/123, then you could do something like this in your theme's template.php file...

function YOURTHEME_preprocess_page(&$vars) {

  $alias=drupal_get_path_alias($_GET['q']);
  $args=explode('/', $alias);
  if ($args[0]=='special') {
    $vars['theme_hook_suggestions'][] = 'page__special';
  }

  // any other page preprocessing here

}

...which takes a dull ax to the url and chops it apart and if the first part is special then it tells drupal to use your page template for it. If, however, you know that all of the nodes there are of a certain type, you could do it this way instead...

function YOURTHEME_preprocess_page(&$vars) {

  if (!empty($vars['node']->type) && $vars['node']->type == 'SPECIAL_TYPE') {
    $vars['theme_hook_suggestions'][] = 'page__special';
  }

  // any other page preprocessing here

}

...which would tell drupal to use your template file whenever it displays a SPECIAL_TYPE node on a full page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.