Last active
December 22, 2015 00:38
-
-
Save rsleggett/6390335 to your computer and use it in GitHub Desktop.
Context Engine Demo Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private bool SmartPhoneContext(HttpContextBase context) | |
{ | |
try | |
{ | |
var contextEngine = new ContextEngine(); | |
return contextEngine.Device.IsMobile && !contextEngine.Device.IsTablet && contextEngine.Device.DisplayWidth > 480; | |
} | |
catch(Exception) | |
{ | |
return false; | |
} | |
} | |
private bool TabletContext(HttpContextBase context) | |
{ | |
try | |
{ | |
var contextEngine = new ContextEngine(); | |
return contextEngine.Device.IsTablet; | |
} | |
catch (Exception) | |
{ | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web; | |
using System.Web.WebPages; | |
using Sdl.Tridion.Context; | |
namespace Your_Website.Classes | |
{ | |
///<summary> | |
/// DemoDisplayModeHelper is responsible for filling the DisplayModeProvider with some custom tests | |
/// Author: Robert Stevenson-Leggett | |
/// Date: 2013-02-15 | |
///</summary> | |
public class DemoDisplayModeHelper | |
{ | |
public void AddDisplayModes(DisplayModeProvider provider) | |
{ | |
provider.Modes.Insert(0, new DefaultDisplayMode("Tablet") | |
{ | |
ContextCondition = (context => TabletContext(context)) | |
}); | |
provider.Modes.Insert(1, new DefaultDisplayMode("SmartPhone") | |
{ | |
ContextCondition = (context => SmartPhoneContext(context)) | |
}); | |
provider.Modes.Insert(2, new DefaultDisplayMode("Mobile") | |
{ | |
ContextCondition = (context => MobileContext(context)) | |
}); | |
provider.Modes.Insert(3, new DefaultDisplayMode("Desktop") | |
{ | |
ContextCondition = (context => DesktopContext(context)) | |
}); | |
} | |
private bool DesktopContext(HttpContextBase context) | |
{ | |
try | |
{ | |
var contextEngine = new ContextEngine(); | |
return !contextEngine.Device.IsMobile && !contextEngine.Device.IsTablet; | |
} | |
catch (Exception) | |
{ | |
return true; | |
} | |
} | |
private bool MobileContext(HttpContextBase context) | |
{ | |
try | |
{ | |
var contextEngine = new ContextEngine(); | |
return contextEngine.Device.IsMobile && !contextEngine.Device.IsTablet && contextEngine.Device.DisplayWidth < 481; | |
} | |
catch (Exception) | |
{ | |
return false; | |
} | |
} | |
private bool SmartPhoneContext(HttpContextBase context) | |
{ | |
try | |
{ | |
var contextEngine = new ContextEngine(); | |
return contextEngine.Device.IsMobile && !contextEngine.Device.IsTablet && contextEngine.Device.DisplayWidth > 480; | |
} | |
catch(Exception) | |
{ | |
return false; | |
} | |
} | |
private bool TabletContext(HttpContextBase context) | |
{ | |
try | |
{ | |
var contextEngine = new ContextEngine(); | |
return contextEngine.Device.IsTablet; | |
} | |
catch (Exception) | |
{ | |
return false; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using DD4T.Mvc.Html | |
@model Your_Website.Models.PresenterViewModel | |
<article> | |
@if(!string.IsNullOrEmpty(Model.Image)) | |
{ | |
<img src="@Model.Image.ResizeToWidth(220)" alt="@Model.Name" /> | |
} | |
<h1>@Model.Name</h1> | |
<p>@Model.JobTitle - @Model.Organisation</p> | |
@Html.Raw(Model.Biography) | |
</article> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using DD4T.Mvc.Html | |
@model Your_Website.Models.PresenterViewModel | |
<article> | |
<h1>@Model.Name</h1> | |
<p>@Model.JobTitle - @Model.Organisation</p> | |
@if(!string.IsNullOrEmpty(Model.Image)) | |
{ | |
<p> | |
<img src="@Model.Image.ResizeToWidth(120)" alt="@Model.Name" /> | |
</p> | |
} | |
@Html.Raw(Model.Biography) | |
</article> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment