mobilelocomotivecms

Locomotive CMS Detect and Display Views for Mobile


I have a LocomotiveCMS site up and running on Heroku. I can edit my templates locally and push using Wagon. It works great!

However, I'd like to be able to serve a separate set of views for mobile devices (phones really) vs desktop/tablet. Can it be done easily? Will it require large modifications to the engine?

EDIT: I should add that I have done this before for a basic Rails app with no issues. I know how to detect a mobile device by examining the user agent and creating a separate folder (such as views_mobile) to store the mobile views. Would like to be able to do the same for LocomotiveCMS


Solution

  • That's a tough question. For the next version of LocomotiveCMS (v3), we'll use a full stack of middleware so that it will be easy to add your own custom behaviors.

    But, for the current version of the engine, it's not that easy. However, I'm thinking about something. Perhaps you could create a Route constraint for the mobile detection (http://guides.rubyonrails.org/routing.html#advanced-constraints).

    Then, you would modify your routes.rb by adding this:

    match '*path' => 'locomotive/public/pages#show', page_path: 'mobile-index', constraint: MobileContraint.new

    Never tested so it might not work :-) Happy patching!

    Didier