NodeOne

Learn Drupal 14i: Templates and theme function

by NodeOne

This screencast is a part of the epic learning series "Four weeks of Drupal", chapter "Introduction to theming". You can view the full series at http://dev.nodeone.se/en/four-weeks-of-drupal.
Please post any comments over there, or we won't see them. Sorry.

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.