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.

All other Modules /

Discuss all other Modules here.

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

Requirements:: in silverstripe-mobile Module Problem


Reply


3 Posts   526 Views

Avatar
tazzydemon

Community Member, 124 Posts

16 February 2012 at 11:55am

Just thought I would make an observation that if one has this in page.php:

      Requirements::themedCSS('layout');
      Requirements::themedCSS('typography');
      Requirements::themedCSS('form');

This this is called before the theme switch onAfterInit in silverstripe-mobile and thus you get the unwanted main theme css in the mobile theme

The fix is simple, move the requirements to the template... but this is deprecated, so what's the official view?

Julian

Avatar
Willr

Forum Moderator, 5513 Posts

20 February 2012 at 7:51pm

The fix is simple, move the requirements to the template... but this is deprecated, so what's the official view?

Including it in the template is not deprecated by any means, the only issue is the template API provides a much smaller set of functionality to the PHP requirements API (e.g you cannot use combine_files())

In your case, I suggest you could do something like this in your Page.php init function.

if($this->onMobileDomain()) {
Requirements::css("your/mobile.css");
}
else {
Requirements::css("your/plain.css");
}

If you're including multiple css files (i.e layout, type and form) perhaps take a look at Requirements::combine_files(), can help speed up a site by reducing http requests.

Avatar
kinglozzer

Community Member, 171 Posts

23 February 2013 at 1:05am

** Mega bump **

I've just been having this trouble, and can't use onMobileDomain() as the site doesn't have a mobile domain. I've written a solution that appears to work perfectly for me, submitted a pull request:

https://github.com/silverstripe/silverstripe-mobile/pull/38

Usage would be:

if($this->requestedMobileSite()) {
Requirements::css("your/mobile.css");
} else {
Requirements::css("your/fullsite.css");
}