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

Requirements:: in silverstripe-mobile Module Problem


Go to End


3 Posts   969 Views

Avatar
tazzydemon

Community Member, 135 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, 5523 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, 187 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");
}