public HttpResponseMessage GetHtml(string id)
        {
            var item     = ID.Parse(id);
            var database = Sitecore.Context.Database;

            Sitecore.Context.Item = database.GetItem(item);
            var personalisedRenderingList = new List <PersonalisedRendering>();

            using (new PersonalisationContext())
            {
                var renderings = PageContext.Current.PageDefinition.Renderings.Where(IsPersonalisedRendering).ToList();

                foreach (Rendering current in renderings)
                {
                    using (StringWriter stringWriter = new StringWriter())
                    {
                        PipelineService.Get()
                        .RunPipeline <RenderRenderingArgs>("mvc.renderRendering",
                                                           new RenderRenderingArgs(current, stringWriter));

                        var personalisedRendering = new PersonalisedRendering()
                        {
                            Id   = current.UniqueId.ToString(),
                            Html = stringWriter.ToString()
                        };

                        personalisedRenderingList.Add(personalisedRendering);
                    }
                }
            }

            return(Request.CreateResponse(HttpStatusCode.OK, personalisedRenderingList));
        }
예제 #2
0
        private void ReplacePlaceholders(string html, TextWriter writer, Rendering rendering)
        {
            var index = html.IndexOf(placeholderStartSearch, StringComparison.Ordinal);

            if (index < 0)
            {
                writer.Write(html);
                return;
            }

            var endOfStartTag    = html.IndexOf(" -->", index, StringComparison.Ordinal);
            var startOfKey       = index + placeholderStartSearch.Length;
            var placeHolderKey   = html.Substring(startOfKey, endOfStartTag - startOfKey);
            var endTag           = string.Format(placeHolderEndSearch, placeHolderKey);
            var endOfPlaceHolder = html.IndexOf(endTag, endOfStartTag, StringComparison.Ordinal);

            if (endOfPlaceHolder < 0)
            {
                throw new Exception("Could not find end of placeholder " + placeHolderKey);
            }
            if (placeHolderKey.IndexOf("_cacheable", StringComparison.Ordinal) > placeHolderKey.LastIndexOf('/'))
            //another way to cache placeholders is to have the name contain _cacheable
            {
                writer.Write(html.Substring(0, endOfPlaceHolder + endTag.Length));
            }
            else
            {
                writer.Write(html.Substring(0, index));
                PipelineService.Get().RunPipeline <RenderPlaceholderArgs>("mvc.renderPlaceholder",
                                                                          new RenderPlaceholderArgs(placeHolderKey, writer, rendering));
            }
            ReplacePlaceholders(html.Substring(endOfPlaceHolder + endTag.Length), writer, rendering);
        }
        protected virtual void Render(string placeholderName, TextWriter writer, RenderPlaceholderArgs args)
        {
            IEnumerable <Rendering> renderings = this.GetRenderings(placeholderName, args);

            if (renderings != null)
            {
                foreach (Rendering rendering in renderings)
                {
                    PipelineService.Get().RunPipeline <RenderRenderingArgs>("mvc.renderRendering", new RenderRenderingArgs(rendering, writer));
                }
            }
        }
예제 #4
0
        protected virtual string Placeholder(string placeholderName, Rendering rendering)
        {
            Assert.ArgumentNotNull(placeholderName, "placeholderName");

            var stringWriter = new StringWriter();

            PipelineService.Get()
            .RunPipeline(
                "mvc.renderPlaceholder",
                new RenderPlaceholderArgs(placeholderName, stringWriter, rendering));
            return(stringWriter.ToString());
        }
예제 #5
0
        public ActionResult EditLayout()
        {
            var pageContext = PageContext.CurrentOrNull;

            Assert.IsNotNull(pageContext, "Page context is required");
            var stringWriter = new StringWriter();

            stringWriter.Write("<html><head></head><body>");
            PipelineService.Get().RunPipeline <RenderPlaceholderArgs>("mvc.renderPlaceholder",
                                                                      new RenderPlaceholderArgs(pageContext.Item["PlaceholderName"] ?? "compositecontent", (TextWriter)stringWriter, new ContentRendering()));
            stringWriter.Write("</body></html>");
            return(Content(stringWriter.ToString()));
        }
        protected override IValueProvider GetValueProvider(HttpContextBase httpContext, RenderingContext renderingContext)
        {
            if (renderingContext.Rendering.Parameters == null)
            {
                return(null);
            }

            var args = new GetControllerRenderingValueParametersArgs(httpContext, renderingContext);

            var parameters = PipelineService.Get().RunPipeline("mvc.getControllerRenderingValueParameters",
                                                               args,
                                                               x => x.Parameters);

            return(new PipelineValueProvider(parameters ?? new Dictionary <string, object>(), CultureInfo.CurrentCulture));
        }
        public override IValueProvider GetValueProvider(ControllerContext controllerContext)
        {
            if (RenderingContext.CurrentOrNull?.Rendering?.Parameters == null)
            {
                return(null);
            }

            var args = new GetControllerRenderingValueParametersArgs(HttpContext.Current, RenderingContext.Current);

            var parameters = PipelineService.Get().RunPipeline("elision.getControllerRenderingValueParameters",
                                                               args,
                                                               x => x.Parameters);

            return(new PipelineValueProvider(parameters ?? new Dictionary <string, object>(), CultureInfo.CurrentCulture));
        }
예제 #8
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IPipelineRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Pipeline>(null));
            var service = new PipelineService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLPipelineMapperMock,
                                              mock.DALMapperMockFactory.DALPipelineMapperMock);

            ApiPipelineResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public void Process(HandlebarHelpersPipelineArgs pipelineArgs)
        {
            pipelineArgs.Helpers.Add(new HandlebarHelperRegistration("placeholder", (writer, context, args) =>
            {
                var passedInName     = args[0].ToString();
                var placeholderName  = args[0].ToString();
                var placeholderIndex = args.Length > 1 ? args[1].ToString() : "1";
                placeholderIndex     = string.IsNullOrEmpty(placeholderIndex) ? "1" : placeholderIndex;

                Guid currentRenderingId = RenderingContext.Current.Rendering.UniqueId;

                if (currentRenderingId != Guid.Empty)
                {
                    placeholderName = String.Format("{0}-{1}-{2}", placeholderName, currentRenderingId.ToString("B"), placeholderIndex);
                }

                if (Sitecore.Context.PageMode.IsExperienceEditorEditing)
                {
                    writer.Write(@"<div data-container-title=""{0}"">", placeholderName);
                }

                //save current context for later
                var oldContext       = HttpContext.Current.Items["HandlebarDataSource"];
                var oldRenderingItem = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering.Item;

                //Helper set from Variant field class as it's passed as arg.
                HtmlHelper helper = HttpContext.Current.Items["htmlHelper"] as HtmlHelper;
                if (helper != null)
                {
                    var placeholderStr = (new Sitecore.Mvc.Helpers.SitecoreHelper(helper)).DynamicPlaceholder(passedInName).ToHtmlString();
                    writer.Write(placeholderStr);
                }
                else
                {
                    //The old manual way where we have no access to helper.
                    PipelineService.Get().RunPipeline <RenderPlaceholderArgs>("mvc.renderPlaceholder", new RenderPlaceholderArgs(placeholderName, writer, new ContentRendering()));
                }
                //put it back.
                HttpContext.Current.Items["HandlebarDataSource"] = oldContext;
                Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering.Item = oldRenderingItem;

                if (Sitecore.Context.PageMode.IsExperienceEditorEditing)
                {
                    writer.Write(@"</div>");
                }
            }));
        }
        protected override void DoRender(HtmlTextWriter output)
        {
            HttpContextWrapper httpCtxWrapper = _pageCtx.RequestContext.HttpContext as HttpContextWrapper;

            if (httpCtxWrapper != null)
            {
                using (ContextService.Get().Push <Sitecore.Mvc.Presentation.PageContext>(_pageCtx))
                {
                    ViewContext viewCtx = CreateViewContext(httpCtxWrapper, _pageCtx.RequestContext.RouteData, _rendering);

                    using (ContextService.Get().Push <ViewContext>(viewCtx))
                    {
                        PipelineService.Get().RunPipeline <RenderRenderingArgs>("mvc.renderRendering", new RenderRenderingArgs(_rendering, output));
                    }
                }
            }
            else
            {
                throw new Exception("Invalid HttpContextWrapper");
            }
        }
예제 #11
0
        public GenPhHtml CreateModel(string placeholderKey)
        {
            string returnHtml     = null;
            Item   currentItem    = RenderingContext.Current.Rendering.Item;
            var    renderings     = new List <Sitecore.Mvc.Presentation.Rendering>();
            var    renderingCount = currentItem.Visualization.GetRenderings(Sitecore.Context.Device, false).ToList();

            if (renderingCount.Count > 0)
            {
                renderings.AddRange(renderingCount.Select(r => new Sitecore.Mvc.Presentation.Rendering
                {
                    RenderingItemPath = r.RenderingID.ToString(),
                    Parameters        = new RenderingParameters(r.Settings.Parameters),
                    DataSource        = r.Settings.DataSource,
                    Placeholder       = r.Placeholder,
                }));



                foreach (var r in renderings.Where(r => r.Placeholder.Contains(placeholderKey)))
                {
                    using (var stringWriter = new StringWriter())
                    {
                        PipelineService.Get()
                        .RunPipeline("mvc.renderRendering", new RenderRenderingArgs(r, stringWriter));
                        returnHtml += stringWriter.ToString();
                    }
                }
            }

            //var imageRenderings = new List<string>();
            //imageRenderings.Add(FieldRenderer.Render(currentItem, "Image", "mw=400"));

            return(new GenPhHtml
            {
                PlaceholderKey = placeholderKey,
                GenHtml = returnHtml,
                ItemID = RenderingContext.Current.Rendering.Item.ID.ToString()
            });
        }
예제 #12
0
        protected virtual string Placeholder(string placeholderName, Rendering rendering)
        {
            Assert.ArgumentNotNull(placeholderName, "placeholderName");
            Assert.ArgumentNotNull(rendering, "rendering");

            var stringWriter = new StringWriter();

            // Append placeholder name with "-dynamic", "_dynamic", ".dynamic" or "#dynamic" in JS component to treat this placeholder as Dynamic
            if (_dynamicPlaceholderRegex.IsMatch(placeholderName))
            {
                // "-dynamic" part will be removed
                var placeholder = _dynamicPlaceholderRegex.Replace(placeholderName, string.Empty);

                // this will render placeholders with appended IDs, which is usually used for dynamic placeholders.
                // you do not need to specify dynamic placeholders in JS (as FE developer might not what is that)
                PipelineService.Get()
                .RunPipeline(
                    "mvc.renderPlaceholder",
                    new RenderPlaceholderArgs($"{placeholder}_{rendering.UniqueId.ToString("D").ToUpper()}",
                                              stringWriter, rendering));

                // TODO: figure out how to get correct index to append placeholder
                PipelineService.Get()
                .RunPipeline(
                    "mvc.renderPlaceholder",
                    new RenderPlaceholderArgs($"{placeholder}-{rendering.UniqueId.ToString("B").ToUpper()}-0",
                                              stringWriter, rendering));
            }
            else
            {
                // standard placeholder
                PipelineService.Get()
                .RunPipeline(
                    "mvc.renderPlaceholder",
                    new RenderPlaceholderArgs(placeholderName, stringWriter, rendering));
            }

            return(stringWriter.ToString());
        }
        /// <summary>
        /// Render step, except it temporarily abandons the placeholder context to render a seperate item, after which it puts the context back
        /// </summary>
        /// <param name="placeholderName">Placeholder to render</param>
        /// <param name="writer">writer to render to</param>
        /// <param name="args"></param>
        protected override void Render(string placeholderName, TextWriter writer, RenderPlaceholderArgs args)
        {
            if (PageRenderItemDefinitionContext.CurrentOrNull != null)
            {
                args.PageContext.PageDefinition = PageRenderItemDefinitionContext.Current.Definition;
            }

            if (placeholderName != ItemRenderingKey)
            {
                base.Render(placeholderName, writer, args);
                return;
            }

            Stack <PlaceholderContext> previousContext = new Stack <PlaceholderContext>();

            while (PlaceholderContext.CurrentOrNull != null)
            {
                previousContext.Push(PlaceholderContext.Current);
                PlaceholderContext.Exit();
            }

            try
            {
                PipelineService.Get().RunPipeline("mvc.renderRendering", new RenderRenderingArgs(args.PageContext.PageDefinition.Renderings.First(x => x.Placeholder.IsWhiteSpaceOrNull()), writer));
            }
            finally
            {
                while (PlaceholderContext.CurrentOrNull != null)
                {
                    PlaceholderContext.Exit();
                }

                while (previousContext.Any())
                {
                    PlaceholderContext.Enter(previousContext.Pop());
                }
            }
        }
        public void Process(HandlebarHelpersPipelineArgs pipelineArgs)
        {
            pipelineArgs.Helpers.Add(new HandlebarHelperRegistration("placeholder", (writer, context, args) =>
            {
                var placeholderName = args[0].ToString();

                Guid currentRenderingId = RenderingContext.Current.Rendering.UniqueId;

                if (currentRenderingId != Guid.Empty)
                {
                    placeholderName = String.Format("{0}_{1}", placeholderName, currentRenderingId);
                }

                if (Sitecore.Context.PageMode.IsExperienceEditorEditing)
                {
                    writer.Write(@"<div data-container-title=""{0}"">", placeholderName);
                }

                //save current context for later
                var oldContext       = HttpContext.Current.Items["HandlebarDataSource"];
                var oldRenderingItem = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering.Item;

                Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering.Item = Sitecore.Context.Item;

                //Updated to do new content rendering, similar to what the composite component does, as this was setting the context to the template.
                PipelineService.Get().RunPipeline <RenderPlaceholderArgs>("mvc.renderPlaceholder", new RenderPlaceholderArgs(placeholderName, writer, new ContentRendering()));

                //put it back.
                HttpContext.Current.Items["HandlebarDataSource"] = oldContext;
                Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering.Item = oldRenderingItem;

                if (Sitecore.Context.PageMode.IsExperienceEditorEditing)
                {
                    writer.Write(@"</div>");
                }
            }));
        }
예제 #15
0
        // GET: Snippet
        public ActionResult CompositeComponent()
        {
            var renderingContext = RenderingContext.CurrentOrNull;

            if (renderingContext == null)
            {
                throw new ApplicationException("Could not find current rendering context, aborting");
            }
            var hasDataSource = !string.IsNullOrWhiteSpace(renderingContext.Rendering.DataSource);
            var pageContext   = new PageContext()
            {
                RequestContext = this.ControllerContext.RequestContext,
                Item           = !hasDataSource ? null : renderingContext.Rendering.Item
            };
            var oldDisplayMode = global::Sitecore.Context.Site != null ? global::Sitecore.Context.Site.DisplayMode : DisplayMode.Normal;

            try
            {
                if (oldDisplayMode == DisplayMode.Edit && global::Sitecore.Context.Site != null)
                {
                    //disable the editing of the nested component
                    global::Sitecore.Context.Site.SetDisplayMode(DisplayMode.Preview, DisplayModeDuration.Temporary);
                }

                using (PlaceholderContext.Enter(new PlaceholderContext("/")))
                    using (ContextService.Get().Push <PageContext>(pageContext))
                    {
                        var htmlHelper = new HtmlHelper(new ViewContext(), new ViewPage());

                        var stringWriter = new StringWriter();
                        if (oldDisplayMode == DisplayMode.Edit)
                        {
                            if (hasDataSource)
                            {
                                UrlString webSiteUrl = SiteContext.GetWebSiteUrl(Sitecore.Context.Database);
                                webSiteUrl.Add("sc_mode", "edit");
                                webSiteUrl.Add("sc_itemid", pageContext.Item.ID.ToString());
                                webSiteUrl.Add("sc_lang", pageContext.Item.Language.ToString());

                                //copied style from bootstrap alert
                                stringWriter.Write("<div role=\"alert\" class=\"alert alert-warning\" style=\"box-sizing: border-box; margin-bottom: 20px; border-top: rgb(250,235,204) 1px solid; border-right: rgb(250,235,204) 1px solid; white-space: normal; word-spacing: 0px; border-bottom: rgb(250,235,204) 1px solid; text-transform: none; color: rgb(138,109,59); padding-bottom: 15px; padding-top: 15px; font: 14px/20px 'Helvetica Neue', helvetica, arial, sans-serif; padding-left: 15px; border-left: rgb(250,235,204) 1px solid; widows: 1; letter-spacing: normal; padding-right: 15px; background-color: rgb(252,248,227); text-indent: 0px; border-radius: 4px; -webkit-text-stroke-width: 0px\">");
                                stringWriter.Write("<a class=\"alert-link\" style=\"box-sizing: border-box; text-decoration: none; font-weight: 700; color: rgb(102,81,44); background-color: transparent\" href=\"");
                                stringWriter.Write(webSiteUrl);
                                stringWriter.Write("\" target=\"_blank\" onmousedown=\"window.open(this.href)\">&quot;");
                                stringWriter.Write(pageContext.Item.DisplayName);
                                stringWriter.Write("&quot; is a 'composite component'. Click here to open it's editor</a><br /></div>");
                            }
                            else
                            {
                                //copied style from bootstrap alert
                                stringWriter.Write("<div role=\"alert\" class=\"alert alert-warning\" style=\"box-sizing: border-box; margin-bottom: 20px; border-top: rgb(250,235,204) 1px solid; border-right: rgb(250,235,204) 1px solid; white-space: normal; word-spacing: 0px; border-bottom: rgb(250,235,204) 1px solid; text-transform: none; color: rgb(138,109,59); padding-bottom: 15px; padding-top: 15px; font: 14px/20px 'Helvetica Neue', helvetica, arial, sans-serif; padding-left: 15px; border-left: rgb(250,235,204) 1px solid; widows: 1; letter-spacing: normal; padding-right: 15px; background-color: rgb(252,248,227); text-indent: 0px; border-radius: 4px; -webkit-text-stroke-width: 0px\">");
                                stringWriter.Write("<a class=\"alert-link\" style=\"box-sizing: border-box; text-decoration: none; font-weight: 700; color: rgb(102,81,44); background-color: transparent\" href=\"\" onmousedown=\"");
                                stringWriter.Write("Sitecore.PageModes.PageEditor.postRequest('webedit:setdatasource(referenceId=");
                                stringWriter.Write(renderingContext.Rendering.UniqueId.ToString("B").ToUpper());
                                stringWriter.Write(",renderingId=");
                                stringWriter.Write(renderingContext.Rendering.RenderingItem.ID);
                                stringWriter.Write(",id=");
                                stringWriter.Write(renderingContext.Rendering.Item.ID);
                                stringWriter.Write(")',null,false)");
                                stringWriter.Write("\" target=\"_blank\">This is a 'composite component' without a datasource. Click here to associate a composite component instance</a><br /></div>");
                            }
                        }
                        else
                        {
                            var enableAync = htmlHelper.GetCheckboxRenderingParameterValue("Enable Async");
                            var baseUrl    = htmlHelper.GetRenderingParameter("Async Fetch Base Url");

                            var componentClass = enableAync ? "composite async" : "composite";
                            var tagAttributes  = htmlHelper.GetContainerTagAttributes(componentClass);

                            var asyncUrl = renderingContext.Rendering.Item.GetItemUrl();
                            if (!string.IsNullOrEmpty(baseUrl))
                            {
                                asyncUrl = baseUrl + "/" + asyncUrl;
                            }

                            var asyncAttr = enableAync ? string.Format(@"data-src=""{0}""", asyncUrl) : string.Empty;

                            stringWriter.Write(string.Format(@"<div {0} {1}>", tagAttributes, asyncAttr));
                        }

                        if (hasDataSource)
                        {
                            var loadAsyncOnly = htmlHelper.GetCheckboxRenderingParameterValue("Load Content Async Only");
                            if (!loadAsyncOnly || oldDisplayMode == DisplayMode.Edit)
                            {
                                PipelineService.Get().RunPipeline <RenderPlaceholderArgs>("mvc.renderPlaceholder", new RenderPlaceholderArgs(pageContext.Item["PlaceholderName"] ?? "compositecontent", (TextWriter)stringWriter, new ContentRendering()));
                            }
                        }

                        if (oldDisplayMode != DisplayMode.Edit)
                        {
                            stringWriter.Write("</div>");
                        }

                        return(Content(stringWriter.ToString()));
                    }
            }
            finally
            {
                global::Sitecore.Context.Site.SetDisplayMode(oldDisplayMode, DisplayModeDuration.Temporary);
            }
        }
예제 #16
0
        // GET: Snippet
        public ActionResult CompositeComponent()
        {
            var renderingContext = RenderingContext.CurrentOrNull;

            if (renderingContext == null)
            {
                throw new ApplicationException("Could not find current rendering context, aborting");
            }
            var hasDataSource  = !string.IsNullOrWhiteSpace(renderingContext.Rendering.DataSource);
            var dataSourceItem = hasDataSource ? renderingContext.Rendering.Item : null;
            var pageContext    = new PageContext()
            {
                RequestContext = this.ControllerContext.RequestContext,
                Item           = dataSourceItem
            };
            var oldDisplayMode = global::Sitecore.Context.Site != null ? global::Sitecore.Context.Site.DisplayMode : DisplayMode.Normal;

            try
            {
                if (oldDisplayMode == DisplayMode.Edit && global::Sitecore.Context.Site != null)
                {
                    //disable the editing of the nested component
                    global::Sitecore.Context.Site.SetDisplayMode(DisplayMode.Preview, DisplayModeDuration.Temporary);
                }
                using (PlaceholderContext.Enter(new PlaceholderContext("/")))
                    using (ContextService.Get().Push <PageContext>(pageContext))
                    {
                        var stringWriter = new StringWriter();
                        if (oldDisplayMode == DisplayMode.Edit)
                        {
                            if (hasDataSource)
                            {
                                UrlString webSiteUrl = SiteContext.GetWebSiteUrl(global::Sitecore.Context.ContentDatabase ?? global::Sitecore.Context.Database);
                                webSiteUrl.Add("sc_mode", "edit");
                                webSiteUrl.Add("sc_itemid", pageContext.Item.ID.ToString());
                                webSiteUrl.Add("sc_lang", pageContext.Item.Language.ToString());

                                //copied style from bootstrap alert
                                stringWriter.Write("<div role=\"alert\" class=\"alert alert-warning\" style=\"box-sizing: border-box; margin-bottom: 20px; border-top: rgb(250,235,204) 1px solid; border-right: rgb(250,235,204) 1px solid; white-space: normal; word-spacing: 0px; border-bottom: rgb(250,235,204) 1px solid; text-transform: none; color: rgb(138,109,59); padding-bottom: 15px; padding-top: 15px; font: 14px/20px 'Helvetica Neue', helvetica, arial, sans-serif; padding-left: 15px; border-left: rgb(250,235,204) 1px solid; widows: 1; letter-spacing: normal; padding-right: 15px; background-color: rgb(252,248,227); text-indent: 0px; border-radius: 4px; -webkit-text-stroke-width: 0px\">");
                                stringWriter.Write("<a class=\"alert-link\" style=\"box-sizing: border-box; text-decoration: none; font-weight: 700; color: rgb(102,81,44); background-color: transparent\" href=\"");
                                stringWriter.Write(webSiteUrl);
                                stringWriter.Write("\" target=\"_blank\" onmousedown=\"window.open(this.href)\">&quot;");
                                stringWriter.Write(pageContext.Item.DisplayName);
                                stringWriter.Write("&quot; is a 'composite component'. Click here to open it's editor</a><br /></div>");
                            }
                            else
                            {
                                //copied style from bootstrap alert
                                stringWriter.Write("<div role=\"alert\" class=\"alert alert-warning\" style=\"box-sizing: border-box; margin-bottom: 20px; border-top: rgb(250,235,204) 1px solid; border-right: rgb(250,235,204) 1px solid; white-space: normal; word-spacing: 0px; border-bottom: rgb(250,235,204) 1px solid; text-transform: none; color: rgb(138,109,59); padding-bottom: 15px; padding-top: 15px; font: 14px/20px 'Helvetica Neue', helvetica, arial, sans-serif; padding-left: 15px; border-left: rgb(250,235,204) 1px solid; widows: 1; letter-spacing: normal; padding-right: 15px; background-color: rgb(252,248,227); text-indent: 0px; border-radius: 4px; -webkit-text-stroke-width: 0px\">");
                                stringWriter.Write("<a class=\"alert-link\" style=\"box-sizing: border-box; text-decoration: none; font-weight: 700; color: rgb(102,81,44); background-color: transparent\" href=\"\" onmousedown=\"");
                                stringWriter.Write("Sitecore.PageModes.PageEditor.postRequest('webedit:setdatasource(referenceId=");
                                stringWriter.Write(renderingContext.Rendering.UniqueId.ToString("B").ToUpper());
                                stringWriter.Write(",renderingId=");
                                stringWriter.Write(renderingContext.Rendering.RenderingItem.ID);
                                stringWriter.Write(",id=");
                                stringWriter.Write(renderingContext.Rendering.Item.ID);
                                stringWriter.Write(")',null,false)");
                                stringWriter.Write("\" target=\"_blank\">This is a 'composite component' without a datasource. Click here to associate a composite component instance</a><br /></div>");
                            }
                        }

                        if (hasDataSource && dataSourceItem != null &&
                            dataSourceItem?.TemplateID == new global::Sitecore.Data.ID(CompositeComponentInstanceTemplateId) &&
                            !string.IsNullOrEmpty(pageContext.Item?["PlaceholderName"]))
                        {
                            PipelineService.Get().RunPipeline <RenderPlaceholderArgs>("mvc.renderPlaceholder",
                                                                                      new RenderPlaceholderArgs(pageContext.Item["PlaceholderName"],
                                                                                                                (TextWriter)stringWriter, new ContentRendering()));
                        }

                        return(Content(stringWriter.ToString()));
                    }
            }
            finally
            {
                global::Sitecore.Context.Site.SetDisplayMode(oldDisplayMode, DisplayModeDuration.Temporary);
            }
        }
예제 #17
0
 public ActionResult <List <Pipeline> > Get() =>
 _pipelineService.Get();
예제 #18
0
        /// <summary>
        /// Renders an item with a layout defined to a string for MVC
        /// </summary>
        /// <returns>HTML of item</returns>
        public virtual void Render(TextWriter writer)
        {
            var originalDisplayMode = Context.Site.DisplayMode;

            // keep a copy of the renderings we start with.
            // running the renderPlaceholder pipeline (which runs renderRendering) will overwrite these
            // and we need to set them back how they were when we're done rendering the xBlock
            var originalRenderingDefinitionContext = RenderingContext.CurrentOrNull?.PageContext?.PageDefinition;

            try
            {
                // prevents editing the snippet in context, so you cannot mistakenly change something shared by mistake
                if (Context.PageMode.IsExperienceEditorEditing)
                {
                    Context.Site.SetDisplayMode(DisplayMode.Preview, DisplayModeDuration.Temporary);
                }

                var pageDef = new PageDefinition
                {
                    Renderings = new List <Rendering>()
                };

                //Extracts the item's layout XML, then parses all of the renderings out of it.
                pageDef.Renderings.AddRange(GetRenderings(GetLayoutFromItem()));

                // Uncovers the main layout rendering
                var pageRenderingArgs = new GetPageRenderingArgs(pageDef);
                PipelineService.Get().RunPipeline("mvc.getPageRendering", pageRenderingArgs);

                //Renders all placeholders for the layout rendering, which would be the entire page
                var renderPlaceholderArgs = new RenderPlaceholderArgs(PerformItemRendering.ItemRenderingKey, writer, pageRenderingArgs.Result)
                {
                    PageContext = new PageContext
                    {
                        PageDefinition = pageDef
                    }
                };

                using (PageRenderItemDefinitionContext.Enter(new PageRenderItemDefinitionContext(pageDef, Item, originalDisplayMode)))
                {
                    PipelineService.Get().RunPipeline("mvc.renderPlaceholder", renderPlaceholderArgs);
                }
            }
            catch (Exception e)
            {
                Log.Error("There was a problem rendering an item to string", e, this);
                if (originalDisplayMode == DisplayMode.Edit || originalDisplayMode == DisplayMode.Preview)
                {
                    writer.Write($"<p class=\"edit-only\">Error occurred while rendering {Item.Paths.FullPath}: {e.Message}<br>For error details, <a href=\"{LinkManager.GetItemUrl(Item)}\" onclick=\"window.open(this.href); return false;\">visit the target page</a></p>");
                }
            }
            finally
            {
                // replace the renderings in the current context with the ones that existed before we ran our sideline renderPlaceholder
                // because they have been overwritten with the xBlock's renderings at this point
                if (originalRenderingDefinitionContext != null)
                {
                    RenderingContext.CurrentOrNull.PageContext.PageDefinition = originalRenderingDefinitionContext;
                }

                Context.Site.SetDisplayMode(originalDisplayMode, DisplayModeDuration.Temporary);
            }
        }