I wrote few helper functions and now I want to add these functions somewhere, so that I can call them from any template files.

Where should I put them?

  • You should avoid using any helper function in template files. – Jimmy Ko Aug 2 '16 at 10:24
  • Why?? Can you please explain it – SaifDeen Aug 2 '16 at 21:25
  • 1
    Putting logics in views layer is a very bad design. If you want to have some dynamic value. You should do it in preprocess function at template.php and pass the value through $variables array to those template files. – Jimmy Ko Aug 2 '16 at 21:32

Helper functions is a bit vague for a description (so there may be better places where to put this, like a custom module), but theme functions are usually put into the template.php file of your theme.

It is not generally adviced to put much php code into your templates however (save for printing variables) - best practice usually calls for the use of alter hooks or other preprocess functions. Get a (small) overview here: template.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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