I'm trying to include the total count of a given node type into a view tpl.php file. I would like to set this variable in the template.php file, so that it is available in the tpl.php file (that way I also don't have sql queries gumming up my template files, which I'm trying to avoid.)

I'm trying to set them the variable with template_preprocess_views_view, but the reference variable never seems to be getting updated. I did some sleuthing and threw in some dpm statements, one in the preprocess function, one in the template, and the result looks like this:

preprocess views_view

(The thrid line prints out the preprocess function with the view name attatached)

So it looks like the issue is the template is being called before my preprocess functions, which means the variable hasn't been updated it yet, but is that correct? Shouldn't the preprocess function be called BEFORE the template is called? Is there another hook that I can use to add a variable to views-view-fields.tpl.php?

1 Answer 1


I think you want to use views hooks, not template preprocess functions. The views query will be run before the template is processed. You can find a list of views hooks here: https://api.drupal.org/api/views/views.api.php/group/views_hooks/7.x-3.x

and from that link, and alex.designworks the hook firing order:

- hook_views_pre_view 
 - hook_views_pre_build 
 - hook_views_post_build
 - hook_views_pre_execute
 - hook_views_post_execute
 - hook_views_pre_render
 - hook_views_post_render

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.