I have 2 different frontpages templates based on user´s device so I have:

- mytheme/page--front.tpl.php
- mytheme/page--frontmob.tpl.php

and I have 2 different view blocks (even they are located in same region(Banner Home area 1) should work based on the frontpage that user is using at the moment)

- View: Available concerts operas ballets pages: Video main
- View: video main mobile

So actually I am using the following code in my template.php

function myclassiclive_preprocess_page(&$variables) {

  if (drupal_is_front_page()) {

     include_once ('sites/all/libraries/Mobile_Detect/Mobile_Detect.php');
      drupal_add_js(drupal_get_path('theme', 'mytheme') . '/js/bluemasters.js');
        $GLOBALS['conf']['cache'] = FALSE;

        if ($detect->isMobile()) {
             $variables['theme_hook_suggestions'][] = 'page__frontmob';  


And the above code is working so when I visit the site on mobile it uses the page__frontmob template which is this=> mytheme/page--frontmob.tpl.php

My page--frontmob.tpl.php is different than my page--front.tpl.php but actually the biggest difference is that in my region Banner Home area 1 should appear the view block => View: Available concerts operas ballets pages: Video main only when site is using this front page=> page--front.tpl.php because I am using this template for desktop user´s BUT if the site is using the frontpage: page--frontmob.tpl.php then the view that should appear on the region Banner Home area 1 must be View: video main mobile but what is happening now that the even the site is showing the right frontpage template whether the site is displayed on desktop or mobile device... but STILL both of the views are displaying without caring the frontpage template using at that moment....

I thought because of the next setting in each one of the block´s configuration... would be enought in order system check´s by itself in what frontpage the user is in order to show only one of the blocks that are located in same region: Banner Home area 1

Both block´s configuration: Setting:

Show block on specific pages:
Only the listed pages  

So in summary what I want is:

  • this frontpage template page--front.tpl.php displays only the view: View: Available concerts operas ballets pages: Video main in the region=> Banner Home area 1

  • and this frontpage template page--frontmob.tpl.php displays only the view: View: video main mobile in the region=> Banner Home area 1

I already have checked the functions THEMENAME_preprocess_region and MYTHEME_preprocess_block(&$variables) but I dont if I have to use one of those? which one I should use in my problem case? and I dont know how I should use them?

Please help!!!! My code is already tetecting which frontpage site uses based on user´s device so that is not the point but the block views displayed in same region based on frontpage site is using or also can be based again on user´s device.

Thank you everyone in advance for your help!

Liz ;)

  • Have you considered using PHP (eg, Pages on which this PHP code returns TRUE (experts only)) for the Block Visibility, eg, instead of using show only on specific pages, put the $detect->isMobile() logic there and return TRUE or FALSE accordingly? (This does require the php module be installed and enabled) – Jimajamma May 30 '14 at 19:00
  • Yes I found it. I will try your suggestion. thank you! – Liz May 30 '14 at 19:17
  • I will like to heard from somebody also a themename_preprocess or another kind of preprocess solution since I want to implement a preprocess solution in my template.php thank you! ;) – Liz May 30 '14 at 21:38
  • what do you want to preprocess exactly? – Jimajamma May 30 '14 at 22:12

Your Answer

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

Browse other questions tagged or ask your own question.