public override void Process(RenderLayoutArgs args) { Assert.ArgumentNotNull(args, "args"); var item = Context.Item; if (item == null) { return; } var itemId = item.ID.Guid; var templateId = item.Template.ID.Guid; var page = Context.Page; var currentLanguage = Context.Language.Name; if (SitecoreFeatureToggles.ShouldReplaceLayout(itemId, templateId, currentLanguage)) { page.ClearRenderings(); var renderings = SitecoreFeatureToggles.GetLayoutReplacement(itemId, templateId, currentLanguage); foreach (var sublayout in renderings.Sublayouts) { var rendering = GetRenderingByItemId(sublayout.SublayoutId, sublayout.Placeholder); if (rendering != null) { page.AddRendering(rendering); } } } else { var originalRenderings = page.Renderings.ToList(); var sublayoutReplacements = SitecoreFeatureToggles.GetAllRenderingReplacements(currentLanguage); var foundReplacement = false; foreach (var replacement in sublayoutReplacements) { for (var i = 0; i < originalRenderings.Count; i++) { var reference = originalRenderings[i]; if (reference.RenderingID.Guid == replacement.Original) { foundReplacement = true; var newRendering = GetRenderingByItemId(replacement.New, reference.Placeholder); originalRenderings[i] = newRendering; } } } if (foundReplacement) { page.ClearRenderings(); foreach (var reference in originalRenderings) { page.AddRendering(reference); } } } }
public override void Process(HttpRequestArgs args) { Assert.ArgumentNotNull(args, "args"); var item = Context.Item; if (item == null) { return; } var itemId = item.ID.Guid; var templateId = item.Template.ID.Guid; var currentLanguage = Context.Language.Name; if (SitecoreFeatureToggles.ShouldReplaceLayout(itemId, templateId, currentLanguage)) { var replacement = SitecoreFeatureToggles.GetLayoutReplacement(itemId, templateId, currentLanguage); if (replacement.NewLayoutId.HasValue) { LayoutItem pageEditLayout = Context.Database.GetItem(new ID(replacement.NewLayoutId.Value)); Context.Page.FilePath = pageEditLayout.FilePath; } } }
public override void Process(BuildPageDefinitionArgs args) { Assert.ArgumentNotNull((object)args, "args"); var item = Context.Item; if (item == null) { return; } var itemId = item.ID.Guid; var templateId = item.Template.ID.Guid; var currentLanguage = Context.Language.Name; var renderingBuilder = new RenderingBuilder(); PageDefinition pageDefinition = args.Result; if (pageDefinition == null) { return; } if (SitecoreFeatureToggles.ShouldReplaceLayout(itemId, templateId, currentLanguage)) { //resolve all the renderings from the featuretoggle var layoutReplacement = SitecoreFeatureToggles.GetLayoutReplacement(itemId, templateId, currentLanguage); var layoutRendering = renderingBuilder.GetRenederingById(layoutReplacement.LayoutId); layoutRendering.RenderingType = "Layout"; pageDefinition.Renderings.Add(layoutRendering); foreach (var sublayout in layoutReplacement.Sublayouts) { var rendering = renderingBuilder.GetRenederingById(sublayout.SublayoutId); if (rendering != null) { pageDefinition.Renderings.Add(rendering); } } } else { base.Process(args); var renderingReplacements = SitecoreFeatureToggles.GetAllRenderingReplacements(currentLanguage); //loop through and replace the one I need to replace foreach (var replacement in renderingReplacements) { ProcessRenderings(pageDefinition.Renderings, replacement, renderingBuilder); } } }