If I override the template file using the code below, can I specify the location of page-ajax.tpl.php? I wanted to leave page-ajax.tpl.php inside my module's directory rather than to place it inside the current theme's folder.

function my_ajax_preprocess_page(&$vars, $hook)
    if (isset($_GET['ajax']) && $_GET['ajax'] == 1)
        $vars['template_file'] = 'page-ajax';

It has to be in either the module defining the theme function or the active theme, unless you want to make override in the theme registry.

Drupal provides a hook: hook_theme_registry_alter that allows you to alter the theme registry and thus also where Drupal would look for template files. Messing too much with this tends to make it blow up into your face, as you alter some default Drupal behaviors.

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.