Views Theming mit Preprocess Functions

Posts zu Drupal Views Theming sind immer spannend, da Views so elementar für die meisten Webseiten ist, und es so viele Möglichkeiten gibt den Output zu verändern. Einen stellt evolvingweb vor:

You can add a helper function to your template.php which will enable you to add preprocess functions to individual views on the fly.

To use this method, you’ll need to override template_preprocess_views in your template.php file like this:

function mytheme_preprocess_views_view(&$vars) {
 if(isset($vars['view']->name {
 function = 'mytheme_preprocess_views_view__' . vars['view']->name;
 if(function_exits($function));
 $function($vars);
 }
 }
} 

To preprocess a particular view, you just need to add a preprocess function appending the name of the view. You can also check for the display_id of the view to ensure that you’re only overriding a single display of that view, in this case block_1. This function replaces the more link with a link to search all events:

function mytheme_preprocess_views_view__events(&$vars) {
 if($vars['display_id'] == 'block_1') {
 $vars['more'] = l(t('Search All Events'), 'search/apachesolr_search', array('query' => 'filters=type:event'));
 }
}

Possibly related posts (automatically generated)