Maybe do something like this in a model file:
import os
is_mobile_client = [code testing for mobile client goes here]
if is_mobile_client:
mobile_view = '%s.mobile.%s' % (request.function, request.extension)
if os.path.exists(os.path.join(request.folder, 'views',
request.controller, mobile_view)):
response.view = '%s/%s' % (request.controller, mobile_view)
For any incoming request, it checks if a '[function].mobile.[extension]'
view exists, and if so, it sets response.view to the mobile view. I haven't
tested it thoroughly, but I think something like this would work.
If all of your mobile-specific actions are restricted to a single
controller, then I suppose you could put this code at the top of that
controller instead of in a model file.
Anthony
On Monday, February 14, 2011 3:47:54 PM UTC-5, Chris wrote:
> Hi all,
>
> I'm making a site on web2py that has a mobile counterpart.
>
> I'd like to be able to, once I've detected that a browser is mobile,
> use a different set of views but share the same controller logic. I
> saw that in an earlier post (http://groups.google.com/group/web2py/
> browse_thread/thread/7277e92b03450784/9dd641c956bd6bc3?
> lnk=gst&q=mobile#9dd641c956bd6bc3<http://groups.google.com/group/web2py/browse_thread/thread/7277e92b03450784/9dd641c956bd6bc3?lnk=gst&q=mobile#9dd641c956bd6bc3>)
>
> we covered the browser sniffing,
> and got that working, but how would I be able to, for example, use
> index.mobile.html instead of index.html if I detect the user is coming
> from a mobile device?
>
> Thanks
> Chris