Created
May 15, 2014 06:08
-
-
Save asmagin/70336fb5982fdf139579 to your computer and use it in GitHub Desktop.
Sitecore MVC: Layout with Device Fall Back
This file contains hidden or 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
| namespace Example | |
| { | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using Sitecore; | |
| using Sitecore.Data.Items; | |
| using Sitecore.Mvc.Extensions; | |
| using Sitecore.Mvc.Pipelines.Response.GetPageRendering; | |
| using Sitecore.Mvc.Presentation; | |
| public class GetLayoutRenderingWithFallback : GetLayoutRendering | |
| { | |
| protected override Rendering SelectLayoutRendering(List<Rendering> renderings, GetPageRenderingArgs args) | |
| { | |
| var result = base.SelectLayoutRendering(renderings, args); | |
| if (result != null) | |
| { | |
| return result; | |
| } | |
| var device = Context.Device; | |
| while (device != null) | |
| { | |
| var b = device.ValueOrDefault((DeviceItem d) => d.ID.ToGuid()); | |
| foreach (var current in renderings.Where(current => current.DeviceId == b && current.RenderingType == "Layout")) | |
| { | |
| // set fallback device as current. | |
| Context.Device = device; | |
| return current; | |
| } | |
| device = Context.Device.FallbackDevice; | |
| } | |
| return null; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment