0

I'm using D7 and module Views Accordion (V 7.x-1.1) for my view. I've created my custom template (e.g views-view-accordion--[name of my view].tpl.php) for customize my view. However, when I want to add some variables in preprocess function, I created the function mytheme_preprocess_views_view__[name of my view](&$vars), I cannot get into this function.

Am I doing something wrong? Thanks in advance.

1
  • Suggestions do not have their own preprocess fucntions. They share the preprocess function of the base template, as @thumbson answered. – J. Reynolds Feb 9 '15 at 18:29
1

You want to use template_preprocess_views_view (see views theme functions)

function MYTHEME_preprocess_views_view(&$variables) {
  $view = $variables['view'];
  if ($view->name == 'my_view_name') {
    // add your variables here
    $variables['YOUR_VARIABLE'] = 'value';
  }
}

$YOUR_VARIABLE should be available in your template file.

4
  • I've tried this solution. I've added $view->style_plugin->options['row-start-open'] = '0';in mytheme_preprocess_views_view function, but when it seems that I can't pass the value in my template file views-view-accordion--[name of my view].tpl.php. I used var_dump($view->style_plugin->options['row-start-open']) in template file, the value is always none – stevey Feb 10 '15 at 8:29
  • Try setting $variables['row_start_open'] = '0'; and see if $row_start_open is a variable in your template file. – thumbson Feb 10 '15 at 14:37
  • I've tried, it doesn't work. In my template file, $row_start_open is null – stevey Feb 10 '15 at 15:08
  • A couple things to check: 1) Are you sure your preprocess function is executing? You may need to check that first. 2) Is your view name correct in $view->name == 'my_view_name' ? It's going to be the machine name of the view. I just tested this with one of my views so it should work. Try clearing your cache and see if that helps. – thumbson Feb 10 '15 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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