3

I always found it difficult to work with template suggestions in Drupal. I'm trying to override those files (html.tpl.php, page.tpl.php, region.tpl.php) for a given url (mysite.com/user-export). So I found this function:

function MYTHEMENAME_process_page(&$variables) {
if (module_exists('path')) {
    $alias = drupal_get_path_alias(str_replace('/edit', '', $_GET['q']));
    if ($alias != $_GET['q']) {
        $template_filename = 'page';
        foreach (explode('/', $alias) as $path_part) {
            $template_filename = $template_filename . '__' . $path_part;
        }
        $vars['theme_hook_suggestions'][] = $template_filename;
    }
}
}

That seemed to work pretty well, I created a file named page--user-export.tpl.php to override the page.tpl.php file and it worked. However, at some point I removed that function, and the template overriding was still working! So I guess in some cases we need to create a function in template.php, and in some other cases, the overriding is done automatically without having to create a function.

So my question is: When to use template suggestions ?

Thanks in advance!

1 Answer 1

3

page--internal-path is already defined by Drupal core as a theme hook suggestion, so adding your own version of it won't really have any effect (just as then removing that version won't have any effect).

You can see a full list of the core-implemented hook suggestions on the Drupal 7 Theme Hook Suggestions page.

The simple answer to the question is that you need to provide your own template suggestions when you require that functionality, and Drupal's core system, or a contributed module, haven't already provided the overrides for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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