Theming views from a module

There are many ways to theme a view, but there are times when you want to theme a view from within your module.  For example, you want to Featurize a feature, it makes sense for the theming of the view to be exported along with the module that's implementing it.

Views provides many theme hooks by default, but the most common ones you'll be overriding will be:

hook_node_insert doesn't have all the updated data

There are times when you try to do something in hook_node_insert, only to find out that the data you need is not there yet.

Try doing it in a shutdown function. 

For example,

function mymodule_node_insert($node) {
  drupal_register_shutdown_function('mymodule_shutdown_function', $node);
function mymodule_shutdown_function($node) {
  // clear the cache
  // do something

Theming Views' exposed filters

  • Copy views-exposed-form.tpl.php from /sites/all/modules/views/theme to your theme's folder
  • Rename it to views-exposed-form--view_name.tpl.php if you want it to apply to all displays of that view
  • Or rename it to views-exposed-form--view_name--display_name.tpl.php if you want it to apply to a specific display of that view


Subscribe to DrupalHowTo RSS