1

I want to have a page (e.g. the one at http://example.com/mypage) shown as a blank page. How can I use a different template for that specific page, to show it as a blank page?

4

You can use a different template for a page by suggesting a new template file that will be used.

This can be done in a theme, by writing its template_preprocess_page(), or in a module by implementing hook_preprocess_page().

function template_preprocess_page(&$variables) {
  if (arg(0) == "node" && arg(1) == "1") {
    array_unshift($variables['theme_hook_suggestions'], "page--custom-template");
  }
}

This code is for Drupal 7; for Drupal 6 you need to replace $variables['theme_hook_suggestions'] with $variables['template_files']. In the case you are using it in a module, template_preprocess_page() needs to be renamed mymodule_preprocess_page(), where "mymodule" is the short name of your module.
Instead of using arg() you can also use request_uri(), but the output returned from this function is similar to "/dr72/devel/php?render=overlay&render=overlay" when Drupal is installed in a subdirectory of the web server's root directory. request_uri() doesn't change an alias into the canonical path; supposing that example.com/node-1-title is an alias for example.com/node/1, in my test site, the function will return "/dr72/node-1-title" while arg(0) and arg(1) would return, respectively, "node" and "1" (the first two elements of the path).

4
  • When i use theme_hook_suggestions , Drupal return a page with content of "page--custom-template.tpl.php" in to the default template. This page content show in the body. i want a blank page. – pdan Jan 1 '12 at 17:54
  • Just use an empty template file; in that way, Drupal will return a page that doesn't even contain any Drupal block. – kiamlaluno Jan 1 '12 at 18:00
  • how can i get url to this page? – pdan Jan 1 '12 at 18:20
  • Use arg(), or request_uri(), taking in consideration what I reported in my answer. – kiamlaluno Jan 1 '12 at 18:52
1

If you want to implement this in code, within a custom theme or module, you need to look into template suggestions.

If you want a ui-based solution, there are a few modules that assist in having custom themes for specific themes/sections of your site. See themekey module, custom page module and page theme module for a few modules that do this.

Personally, I would opt for a template suggesion in a custom module.

3
  • I want a code but when i use "template suggestion" , the page has default template at section "<head>". I need a blank page with different template. Happy new year man. – pdan Jan 1 '12 at 17:55
  • This is easy to do in a custom theme. See this link for various examples: drupal.org/node/1041768. – stefgosselin Jan 1 '12 at 20:34
  • oh tnx alot my friend. i take it. – pdan Jan 2 '12 at 5:06
0
function yourTheme_preprocess_html(&$vars) {
  if ($node = menu_get_object()) {
    if($node->type == "mypage") {
      $vars['theme_hook_suggestions'][] = 'html__mypage';
    }
  }
}

then we can access to this page from : http://yoursite.com/?q=mypage or in clear url mode : http://yoursite.com/mypage/

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.