Switching between templates and theme functions

This screencast shows that theme functions and template files are actually interchangable from a theme layer point of view. That means that it doesn't matter if you have a template file called field--body--page.tpl.php, or a theme function called MYTHEME_field__body__page. Both works for overriding the same thing!

So, when do you want to use one or the other?

  • Template files are usually easier to read, override and change. If you expect that your theme function will be overridden a lot, consider making it a template file instead.
  • Template files should not contain much logic. If your theme output requires that, a theme function is probably a better approach. Or make sure to have preprocess function that make the necessary data easily available.
  • If everything else is equal, go for theme functions. They are slightly quicker to execute.
Modules: 
Additional Resources: