0

This question already has an answer here:

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.

marked as duplicate by Clive Jun 27 '14 at 10:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

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.