Everytime I use drupal hooks I always take the custom module route and call the hooks from there. I'm basically talking about all the hooks in drupal -- hook_form_alter(), hook_page_alter(), hook_menu, hook_user(), hook_nodeapi(), hook_init, etc. etc. etc. etc.

On the other hand, I have never actually delve into writing hooks inside my template.php so I was wondering:

- If this is possible?
- Is it going to work exactly the same as it does when called in a module?
- Are all drupal functions available as well through template.php?
- Are there any notable differences in code implementation?
- In which scenario I would choose custom module over theme.php?

Please note any D6 and D7 difference.

Please advice. Thank you.


Some hooks you can call inside template.php, but not all hooks - it really depends on what you're doing. If you keep it mostly theming related (altering data output, adding CSS, form alters, etc), you should be okay. A hook like hook_search_api_query_alter wouldn't work.

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