Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

mobile: using the wrong theme?


Go to End


12 Posts   4092 Views

Avatar
dacar

Community Member, 173 Posts

14 September 2010 at 10:56pm

Edited: 14/09/2010 10:56pm

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.

Avatar
dacar

Community Member, 173 Posts

17 September 2010 at 1:55am

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?

Avatar
Willr

Forum Moderator, 5523 Posts

17 September 2010 at 3:10pm

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.

Avatar
dacar

Community Member, 173 Posts

17 September 2010 at 10:17pm

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.

Avatar
Tonyair

Community Member, 81 Posts

21 September 2010 at 4:57am

Just add this is lines to Page_Controller:init()

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

Avatar
adesweb

Community Member, 39 Posts

21 September 2010 at 5:13am

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 :)

Avatar
Tonyair

Community Member, 81 Posts

21 September 2010 at 6:44am

Edited: 21/09/2010 6:51am

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.

Avatar
adesweb

Community Member, 39 Posts

21 September 2010 at 8:28pm

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

Go to Top