2

In my drupal. I created a two theme one for desktop and another for mobile using Mobile switch I change the theme. Now I Created a View as a page for desktop with alias "xxx/yyy" and for mobile also I created a view as a page with same alias "xxx/yyy"(some modification Done). While switching the theme from desktop to mobile, the desktop view is appear. How to differentiate?

2
  • Do you prefer developing solution or solution that can do it in views?
    – Yuseferi
    Sep 17, 2014 at 17:06
  • developing solution
    – vinox
    Sep 17, 2014 at 17:16

2 Answers 2

3

ok

create a menu with hook_menu then with checking condition you want load your views in callback of your menu

Something like below

/**
 * Implements hook_menu().
 */
function mymodule_menu() {
  $items['myurl'] = array(
    'title' => 'title',
    'page callback' => 'myfunction_callbackfuction',
    'access callback' => TRUE,
  );

  return $items;
}

function myfunction_callbackfuction() {
  $view = views_get_view('view_name');
if($mycondtion)
  $view->set_display('page1');
else 
  $view->set_display('page2');

  $view->pre_execute();
  $view->execute();
  print $view->render();
}
2
  • is it any hook function to disable the particular view.
    – vinox
    Sep 17, 2014 at 18:35
  • @vinox you can create 2 master views without any page or block
    – Yuseferi
    Sep 17, 2014 at 20:17
0

I achieve this by using

$view_name = 'my_views_name';
$display_id = 'my_views_display_id';
print views_embed_view($view_name , $display_id);

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.