3

Feels like a silly question to ask, but I can't find a definitive answer anywhere.

Background

My project is a multi-site that features several themes that our users can choose from. These are all installed in /sites/all/themes. For one site in particular, I wanted to simply use a different page.tpl.php file. I tried copying the theme's page.tpl.php file into /sites/my_site/themes, but this didn't seem to work. This leads me to the question:

In order to override a template, must I use a sub-theme?

1
  • It's not silly. It's only fundamental.
    – Mołot
    Commented Aug 18, 2015 at 14:29

2 Answers 2

1

The correct answer is no since you can also override templates in a module (example). It doesn't sound like you want to do that, though.

At minimum you would have to create an *.info file that includes the dependency:

name = My Theme
description = Just a basic theme
core = 7.x
base theme = base_theme_name
4
  • Thanks for the quick answer. I was beginning to suspect as much, but wanted confirmation. Do you mind expanding just slightly on what you mean by "since you can also override templates in a module"? Commented Aug 18, 2015 at 14:05
  • @BeauTownsend, if I'm not mistaken he means implementing hook_theme_registry_alter.
    – Watergate
    Commented Aug 18, 2015 at 14:07
  • Ah, I understand! Many thanks to both of you! I wish i could award the answer to both of you, but othermachines was the first. :-) Commented Aug 18, 2015 at 14:09
  • Glad to help. There are actually a few examples of overriding templates and theme functions kicking around DA. Here's one: Override default table template In custom module Commented Aug 18, 2015 at 14:14
1

There are multiple ways you could do this. As othermachines writes you can create a subtheme, however, you could also create a custom module and implement hook_theme_registry_alter:

Alter the theme registry information returned from hook_theme().

The theme registry stores information about all available theme hooks, including which callback functions those hooks will call when triggered, what template files are exposed by these hooks, and so on.

Note that this hook is only executed as the theme cache is re-built. Changes here will not be visible until the next cache clear.

In this way you can overwrite (the location of) your .tpl.php file, which will be used instead to create the output.

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.