When overriding templates: think of the children!

The Drupal template override system is very intuitive: find the template you want to alter, copy it to your theme folder and adjust it. The handbook page on d.o about overriding themable output is even one of the most complete and appealing I've seen. So I was surprised when I wanted to override the core poll module's "Most recent poll" block, and found out it simply wasn't working. Try as I might the altered poll-results-block.tpl.php that was sitting in my custom theme folder wasn't being recognized, no matter how many times I cleared the registry or double-checked the paths and filenames. I had my Eureka moment want I came across this d.o issue about how themes can't use node-story.tpl.php without node.tpl.php. John Albin explains the history of this issue (and why it won't be fixed in Drupal 6) in comment #48.

The issue is fixed in Drupal 7 but just so you know in Drupal 6...

  • if you want to override poll-results-block.tpl.php you need to copy poll-results.tpl.php as well.
  • if you want to override comment-blog.tpl.php you need to copy comment.tpl.php as well.
  • if you want to create a Zen subtheme with region-sidebar-first.tpl.php you need to copy region.tpl.php as well.

Comments

Untuitive

Now there's a good word.

Thanks, fixed ;)

Thanks, fixed ;)

Same for page.tpl.php too

I've had the same problem in the past - wasted hours (actually... minutes) trying to figure out why page-front.tpl.php wasn't working. Turns out you need page.tpl.php too! (It was using a base theme so I hadn't got a page.tpl.php until then.

I have had the same problem

I have had the same problem in the past when I forgot to upload the page.tpl.php which I had as a local copy.

Good to see it's fixed in Drupal 7.

I am hugging my computer screen.

Thanks a ton ! This helped.

Thank you for pointing that

Thank you for pointing that out and saving my time.

After spending hours trying

After spending hours trying to figure out why this wasn't working I ran across this post (after running a billion different search phrases through Google) - and fixed my problem in seconds. A billion thanks yous.

Post new comment

The content of this field is kept private and will not be shown publicly.