Jump to:

10842 Posts in 2513 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » mobile: using the wrong theme?

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 2023 Views
  • dacar
    Avatar
    Community Member
    168 Posts

    mobile: using the wrong theme? Link to this post

    Hi,

    first of all i am wondering why there are no topics about the mobile-module in this forum. I think it is really useful. Thanks for it!

    I think i have installed it correctly. On SiteContent i have got the mobile tab. blackcandymobile has been copied to themes. Mobile users are redirected to mobile domain works fine. But the mobile theme is not used. I have installed the User-Agent-Switcher add-on for firefox and tested it on different sites. The add-on works fine, too. But silverstripe uses the standard theme instead of the mobile theme? Can anybody give a hint?

    Have a look on my playground:
    http://www.flavourtripping.de/ and http://mobile.flavourtripping.de/

    Greetings from Germany, Carsten.

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: mobile: using the wrong theme? Link to this post

    Hi,

    unfortunately i still havent solved the problem.

    I have switched the user agent to iPhone3 and tested it on different websites. my Firefox is detected as an iPhone.
    If i put the following to line 40 of MobileSiteControllerExtension.php: echo $config->MobileTheme; die(); I will get "blackcandymobile".

    But the site is rendered with the non mobile standard theme.

    I am using subsites. Can anybody help?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: mobile: using the wrong theme? Link to this post

    first of all i am wondering why there are no topics about the mobile-module in this forum. I think it is really useful. Thanks for it!

    Glad you like it! Not many topics on it because it is no new. Still in beta and not quite feature complete so I guess a few people are waiting till it becomes more robust before trying it out. I just tried with my mobile device and I got the mobile theme on all occasions. Perhaps try including a ?flush=1 when you visit the cache to ensure that the css / Page.ss files are refreshed.

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: mobile: using the wrong theme? Link to this post

    Hi Willr,

    it's working, because i have added a new subsite called http://mobile.flavourtripping.de

    But if you choose this solution, you have to build a separate sitetree for this subsite. What do i have to do if i want to show the sitetree from the main site for mobile users?

    Greetings from germany, Carsten.

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: mobile: using the wrong theme? Link to this post

    Just add this is lines to Page_Controller:init()

          if(MobileSiteControllerExtension::onMobileDomain()){
             $config = SiteConfig::current_site_config();
             SSViewer::set_theme($config->MobileTheme);
          }

  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: mobile: using the wrong theme? Link to this post

    Looking at using this for our agency mobile site. I had to make a few modifications of my own though as we wanted to have the ability to switch between mobile and desktop versions (even if viewing on wrong environment). My code is a bit rough (more of a front-end guy) but I changed MobileSiteControllerExtension.php onBeforeInit function to this:

    public function onBeforeInit() {
          $config = SiteConfig::current_site_config();
          $env = '';
          
          //Get cookie value
          if(isset($_COOKIE['env'])&&($_COOKIE['env']=="m"||$_COOKIE['env']=="d")){
             $env = $_COOKIE['env'];
          }
          
          // Redirect users to the full site if requested (cookie expires in 30 minutes)
          if(isset($_GET['env'])) {
             if($_GET['env']=="d"){
                $_COOKIE['env'] = "d";
                setcookie('env', "d", time() + self::$cookie_expire_time);
                $env = "d";
             }elseif($_GET['env']=="m"){
                $_COOKIE['env'] = "m";
                setcookie('env', "m", time() + self::$cookie_expire_time);
                $env = "m";
             }
          }

          // Redirect to the full site if user requested
          if($this->onMobileDomain() && $config->MobileSiteType == 'RedirectToDomain' && $env == "d") {
             return $this->owner->redirect($config->FullSiteDomain);
          } elseif($env == "d") {
             return; // nothing more to be done
          }

          // If the user requested the mobile domain, set the right theme
          if($this->onMobileDomain()) {
             SSViewer::set_theme($config->MobileTheme);
          }

          // User just wants to see a theme, but no redirect occurs
          if((MobileBrowserDetector::is_mobile()||$env=="m") && $config->MobileSiteType == 'MobileThemeOnly') {
             SSViewer::set_theme($config->MobileTheme);
          }

          // If on a mobile device, but not on the mobile domain and has been setup for redirection
          if(!$this->onMobileDomain() && (MobileBrowserDetector::is_mobile()||$env=="m") && $config->MobileSiteType == 'RedirectToDomain') {
             return $this->owner->redirect($config->MobileDomain);
          }
       }

    In order to switch to mobile, just add ?env=m, and to switch to desktop use ?env=d.

    Sure someone else could make it a little more efficient though

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: mobile: using the wrong theme? Link to this post

    Why not mobile.sitename.com and sitename.com for full version it works even if u use wrong environment if u turn off redirection?

    Also u can add director rules to project/_config.php something like: Director::addRules(50,array('mobile' => 'Page/mobile'));
    and define mobile method in Page_Controller where u can add cookies or session variables and of course theme selector.

  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: mobile: using the wrong theme? Link to this post

    Hi,

    You're probably right. I have created a mobile domain, and reverted to the original code and it seems to be a lot better way of doing it. Only thing it lacks is the ability to switch back to mobile site (what if a user clicked it accidentally for example) without waiting 30 mins, but I guess this is where that Director::addRules stuff comes in. Will have to look into. Thanks for the pointers

    Adrian

    2023 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.