I would like to know how to display a template for mobile users, and a template for desktop users on a j2.5 site? Is this possible without using a sub domain?
If not, then what is the most efficient way to detect a mobile user, and display an alternative .css file only (as opposed to a different template)?
You can detect the users browser (including mobile) via the browsers User Agent. In PHP this is available through
which will display a string like
That’s my current user agent using Chrome on a MacBook.
You can run a regex match against this string to match to known mobile browsers and redirect the to a mobile version of the site. Most websites use a
m.ormobile.subdomain.