My view fields are as like shown in screenshot, for each row I need to add comment link,revision link ,edit link, voting icons and topic terms etc And I have large number of views which will share all these fields.

enter image description here

So I thought to remove all the fields and have nid field in all my views. Then create common template file of nid. And in that template file I am planing to use node_laod and fetch all required fields and add them with some common required html structure.

Please suggest if this will be right way to achieve such kind of workflow and reducing work load to add fields in each view, make them easy to edit or make change in fields from template files.

Is this will be good idea to write php code in template file or I am supposed to use some pre process functions etc

Please suggest ! Thanks.

2 Answers 2


No. Do not make a view that pulls a nid, then do node_load in the template. This will be a performance killer.

You should create a view mode using Entity View Mode module, add the fields to the display, and theme it with node--node-type--view-mode.tpl.php. Then the configured View only has to show 'Rendered Content' - and pick the view mode. Then you're done.

See: https://www.youtube.com/watch?v=wcskTtvR6Mo

  • Thanks you! I will look into this and try according to your suggestion.
    – jas
    Mar 3, 2017 at 18:31
  • I have gone thorugh video but view modes only allow to create view mode with available fields of content type and the we can use them in views. But in my case I need to fetch voting contorles (used with rate module) , node edit link , comment form link with count of comments, revisions link with rev count. Is that possible without using templates, please suggest !
    – jas
    Mar 3, 2017 at 18:56
  • It is easy to create those links in a preprocess.
    – Kevin
    Mar 3, 2017 at 19:00
  • sorry for bothering but is I have to use some kind of this hook drupal.stackexchange.com/questions/60271/… to add such links. I have not done such kind of thing before so just want to handle all views with manageable way, any links to read more or example will be very helpful :)
    – jas
    Mar 3, 2017 at 19:07

It is not a good practice to put php processing in template files. Try to have only variables with the necessary information there and if-then blocks to decide what you need to print in the html. You can preprocess your data in template.php or a module.

But I would go for the "fetch as much as possible in the view" approach. You will actually gain a bit of performance and, as I understand your requirements, you will have all you need, just have to style it. On that point you can go either for different templates for every view, a more common template for multiple views (see the theming information), or even group some of the views creating different displays and providing common/separate templates as needed.

  • Thanks for comments, if I use fields in views and I have to make change in one field then I have to edit all views and alter fields. That will b helpful if its possible to provide any links to study :)
    – jas
    Mar 3, 2017 at 11:02
  • Well, using a single template can also have its gotchas - for example, if you want to show different fields/arrangements in different circumstances. You'll have to choose the less evil, I guess :)
    – kufeiko
    Mar 3, 2017 at 11:15

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.