Developer forum

Forum » Templates » Device layout question

Device layout question

Dmitrij Jazel
Reply

Hello DW guys,

I am trying to use device layouts for defining mobile template on plain CMS DW website.

What I wanted to know is - how DW is defining that the device is "mobile" and now it must use "mobile template"?

It's cause I have an iPad, that must see webpage as mobile device - but it tries to open page normally - eventually that brakes the layout.

Any suggestions, or maybe someone knows how DW is deciding on device layout?

 

Regards,

Dmitrij


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Dmitri,

 

With a little bit of Reflector, I found this:

 

private void DetectTypeAndPlatform()
{
    string str = string.Empty;
    if (!string.IsNullOrEmpty(Input.Request("devicedetect")))
    {
        HttpContext.Current.Session["devicedetect"] = false;
    }
    if (HttpContext.Current.Session["devicedetect"] == null)
    {
        try
        {
            str = HttpContext.Current.Request.UserAgent.ToLower();
        }
        catch (Exception exception1)
        {
            ProjectData.SetProjectError(exception1);
            Exception exception = exception1;
            ProjectData.ClearProjectError();
        }
        if (str.Contains("iphone") || str.Contains("ipod"))
        {
            this._Device = DeviceType.Mobile;
            this._Platform = PlatformType.Ios;
        }
        else if (str.Contains("ipad"))   
        {             
           this._Device = DeviceType.Tablet;             
           this._Platform = PlatformType.Ios;         
        }
        else if (str.Contains("android"))
        {
            this._Platform = PlatformType.Android;
            if (str.Contains("mobile"))
            {
                this._Device = DeviceType.Mobile;
            }
            else
            {
                this._Device = DeviceType.Tablet;
            }
        }
        else if (str.Contains("windows phone os 7"))
        {
            this._Device = DeviceType.Mobile;
            this._Platform = PlatformType.Windows;
        }
        else if (str.Contains("tablet") && str.Contains("windows"))
        {
            this._Device = DeviceType.Tablet;
            this._Platform = PlatformType.Windows;
        }
        else if (this.IsBot)
        {
            this._Device = DeviceType.Bot;
            this._Platform = PlatformType.Other;
        }
        NotificationManager.Notify("DWN_STANDARD_PAGE_DEVICEDETECTED", new Standard.Page.DeviceDetectedArgs(this, this._Platform, this._Device));
    }
}

 

As you can see, an iPad is marked as a tablet which seems like the right thing to do (although I wonder if that still holds for an iPad mini).

 

You can extend the way the device is detected using a NotificationSubscriber. The following (untested) shows the idea:

 

using System.Web;
using Dynamicweb.Extensibility;
using Dynamicweb.Frontend;
using Dynamicweb.Notifications;

namespace YourApp
{
  [Subscribe(Standard.Page.DeviceDetected)]
  public class PageDeviceDetectedObserver1 : NotificationSubscriber
  {
    public override void OnNotify(string notification, NotificationArgs args)
    {
      var deviceDetectedArgs = args as Standard.Page.DeviceDetectedArgs;
      if (deviceDetectedArgs == null)
      {
        return;
      }
      string agent = HttpContext.Current.Request.UserAgent.ToLower();
      if (agent.Contains("ipad"))
      {
        deviceDetectedArgs.Device = PageView.DeviceType.Mobile;
      }
    }
  }
}

Dynamicweb's device detection is quite crude; you could also use services like WURFL or 51Degrees.

 

Hope this helps,

 

Imar

 

 

 
Dmitrij Jazel
Reply

Hej Imar,

Thanks alot for lightning fast reply :)))

That's exactly what I needed!

and thanks alot for help!

Dmitrij

 

You must be logged in to post in the forum