3

I have a page with url ?q=admin/settings/history . Is there any way by which I can change the template for this page alone. I tried using hook_preprocess_page but I was unable to change the layout of page. Could someone please lead me in the right direction?

9

Yet another solution, in a couple of lines of code, is:

hook_custom_theme

Return the machine-readable name of the theme to use for the current page. This hook can be used to dynamically set the theme for the current page request. It should be used by modules which need to override the theme based on dynamic conditions

e.g

/**
 * Implements hook_custom_theme
 */
function MYMODULE_custom_theme() {
  // Set path specific theme.
  if (current_path() == 'admin/settings/history') {
    return variable_get('custom_theme', 'theme_name');
  }
}

Core example: system_custom_theme

Update: To use a specific template you can override page.tpl.php

  • copy page.tpl.php to page--admin--settings--history.tpl.php, clear caches (theme registry) and use that.

More info: https://drupal.org/node/1089656

  • tanx for the response.Should i be create a new custom theme or is there a possiblility to link my page to a custom.tpl.php page..?? – Outlooker Dec 16 '13 at 15:28
  • Hey, to use a custom page.tpl.php you can just copy page.tpl.php to page--admin--settings--history.tpl.php, clear caches and use that. More info: drupal.org/node/1089656 – David Thomas Dec 17 '13 at 10:27
5

It looks like you might be looking for a ThemeKey module:

ThemeKey allows you to define simple or sophisticated theme-switching rules which allow automatic selection of a theme depending on current path, taxonomy terms, language, node-type, and many, many other properties. It can also be easily extended to support additional properties exposed by other modules

Emphasis mine.

You can either use it directly, or use it's source code as an example - it's GPL, so you have the right to do it.

  • @Mołot tanx for the response sir,but is there any posssibility by which i could link this to a tpl.php page.?? – Outlooker Dec 16 '13 at 15:41
  • @Outlooker - yes, by creating a child theme with only that one tpl changed, and then setting this new theme for your path. – Mołot Dec 16 '13 at 15:43
  • In D6 i used $variables['template_file'] = 'testing'; where i could use a tpl page named testing.tpl.php.In D7 I shud be creating a sub theme..??Sorry @Mołot,am not really familiar with creating a subtheme. – Outlooker Dec 16 '13 at 15:49
3

In a simple way you can change the theme key by checking the condition,

/**
 * Implements hook_init().
 */
function <module_name>_theme_init() {
    global $theme_key;

    if ($_GET['q'] == "admin/settings/history") {
        $theme_key = '<Your new Theme key>';        
    }
}
  • 3
    For Hook_init it's worth to remember: "Perform setup tasks for non-cached page requests." So on cached pages results may get funny. Also, there is no hook_init in Drupal 8, so using it now is deliberately asking for trouble with future migration / upgrade. Last but not least, I strongly suggest using arg() instead of $_GET. – Mołot Dec 16 '13 at 10:00
2

You can use Page Theme module

The Page Theme module is a simple and easy module to use which allows to use different themes than the site default on specific pages.

enter image description here

  • You cannot override the admin section using page theme module – Bala Varadarajan Dec 16 '13 at 9:54
0

I would suggest to implement a custom module that changes the theme being used for specific pages. It is enough to implement hook_custom_theme() as follows:

function mymodule_custom_theme() {
  if (arg(0) == '' && is_numeric(arg()) && arg(3)== history
) {
    return 'go theme page what you want yo use';
  }
}

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.