I am using drupal 7.

I have one query that when to use a preprocess function instead of changing the template files?

  • 1
    If you can provide more/exact details rather than saying "changing of template file", you will get quicker/best answers
    – NTT
    Aug 24 '16 at 11:47

From the docs

The main role of the preprocessors is to set up variables to be placed within the template (.tpl.php) files.

And building on that:

There can be numerous preprocessors for each theming hook. Every layer from core, modules, engines and themes can have one, each progressively building upon the variables before being rendered through template files. This keeps the markup clean and easy to work with inside templates by placing most of the logic inside these preprocessors.

So if you're setting up a variable that you want to be rendered in a template, your code will go in a preprocess function.

When it's time to render the variables that have been set up, wrap them in specific markup and so on, you'll be editing template files.


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.