0
votes

Using Orchard 1.8.1 I have written a simple image gallery that displays thumbnails and a lightbox. It is just a template that is driven by an Orchard Projection, using a Shape Layout. Works just fine. However, for phone users there is no point displaying thumbnails and it's better to just display the lightbox (with touch support). So I have also implemented that in a separate template. But how can I get Orchard to switch templates depending on the UserAgent string?

I have tried implementing Theme switching (http://weblogs.asp.net/bleroy/dynamically-switching-the-theme-in-orchard), but it's a really ugly solution when I really want to just replace one view, and still enable implementers to switch themes. This is NOT an issue of styling; it's an issue of changing the content based on the device.

I tried implementing DisplayModeProvider as described here: http://www.campusmvp.net/blog/displaymodes-in-mvc-4. But although the filter was called, it had no effect on view names.

Are Projections problematic here because the shape name is set? Is there a better way to go about this?

1
Why not create an alternate when you detect a mobile browser?Bertrand Le Roy
So the idea would be to add the alternate in OnDisplaying() when a phone is detected, and set Placement so that the phone template has higher priority?Dave Gardner
Well, that's just what I did and it works. If you want to promote your suggestion to a reply I will mark it as the answer. Bertrand, thank you!Dave Gardner
I don't know what you mean about placement and about template priority, but I'll add an answer.Bertrand Le Roy
Ah, I see. I just removed the Placement.ini file and it still works fine.Dave Gardner

1 Answers

0
votes

Create an alternate when you see a mobile browser, preferably from a shape table provider.