There are two possible solutions ( php field and view field are not recommended as I know ) to override output of a view field

  1. Create template (tpl) file for field and code for desired output
  2. Use hook hook_views_pre_render

as per the various articles, its not good to have too much templates in drupal.

which approach is good and loads fast ?

2 Answers 2


as per the various articles, its not good to have too much templates in drupal.

With respect, and depending on exactly what you mean by "too much", that's pretty much nonsense. If we're talking about 10,000 template files on an uncached site, then yeah, you would probably have problems. But those problems would be with your application's design; in the real world, with a normal application, that statement is just untrue.

which approach is good and loads fast ?

Both are 'good' (or 'bad'), depending on your point of view, and how well you write the code for them; differences in load times will be negligible, especially with caching. If you're really worried about micro-optimising, then you need to benchmark your site, while it's under load and sitting on production hardware; that's the only way you'll know which method is faster for your use case.

It's not possible to give a blanket "this way is quicker" statement, because it depends on what the rest of the site is doing, how you have it and the server configured, and how good your code is. Always test in the real world rather than ask for others' experiences - you have no way to know if their experiences actually apply to your scenario.

  • on my project I am having around 40 templates and most of them ( 25-30 ) are for views and as its not complete yet i think template count will be > 100
    – Vikram
    May 27, 2015 at 10:01
  • Which should cause you no problem at all, assuming you have proper caching set up, and you're not trying to use 100+ template files on a single page. What you're into right now is an area called "premature optimisation"; it's wise to plan for these things of course, but unless you have a problem to solve, this is time you could spend worrying about something more important
    – Clive
    May 27, 2015 at 10:09

It depends on what you you need to alter if you need to add new layout to set html tags surely .tpl would be the best solution.

If you need to do some checks on fields and do some logic before display fields you could user the pre render hook.

And you could use the two solutions on your needs.

About loading I see tpl file may be loading fast as the theme registry cached form my point of view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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