0

since yesterday I can not solve the problem with function preprocess_views_view: In the views named 'Calendar' I have a few display page(page_classic, page_mobile) and I would like to change preprocess_views_view function in mobile version of the site, which replace default display page(page_classic) with page_mobile. Below function, does not work:(

function mobiletheme_preprocess_views_view(&$vars){
    dpm($vars);
    $view = views_get_view('calendar');
    if($view->name=='calendar'){
        $display_id = 'page_mobile';
        $view->current_display = $display_id;
    }
}

Any ideas?

1

Views' hooks are called whenever a View is called, yet you are calling the creation of the View once again inside of it, and then trying to change that View, not the original one.

Instead, you should be doing something along the lines of...

function mobiletheme_preprocess_views_view(&$vars) {

  $name=$vars['name'];
  $display_id=$vars['display_id'];

  switch ($name) {

     case 'calendar':

       // process it here, eg change/add $vars['foo']
       break;

     // other Views here

  }

}

Now, that, changing template variables, doesn't appear to be what you want to be doing, so you will have to look into some of the other Views hooks, most probably views_pre_view to change the display, eg, something like...

function mobiletheme_views_pre_view(&$view, &$display_id, &$args) {

  if ($view->name=='calendar' && display_id=='page_classic') {
    $view->set_display('page_mobile');
  }

}   

Addition/Caveat: This appears to have to be called from a module, not a theme (at least in D6), so you may need something like this...

function mobilemodule_views_pre_view(&$view, &$display_id, &$args) {
  global $theme;

  if ($theme=='mobiletheme' && $view->name=='calendar' && display_id=='page_classic') {
    $view->set_display('page_mobile');
  }

}   

...inside a small module.

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.