/// <summary> /// Initializes a new instance of the <see cref="TooltipMarker"/> class. /// </summary> /// <param name="renderingContext">The rendering context.</param> /// <param name="placeholderContext">The placeholder context.</param> public TooltipMarker(RenderingContext renderingContext, PlaceholderContext placeholderContext) { Assert.ArgumentNotNull((object)renderingContext, "renderingContext"); Assert.ArgumentNotNull((object)placeholderContext, "placeholderContext"); this.renderingContext = renderingContext; this.placeholderContext = placeholderContext; }
public PlaceHolderMarker(PlaceholderContext placeholderContext, PageContext pageContext) { _placeholderContext = placeholderContext; _pageContext = pageContext; Assert.IsNotNull((object)placeholderContext, "placeholderContext"); Assert.ArgumentNotNull((object)pageContext, "pageContext"); }
private RenderingChrome GetPlaceHolderChrome(string placeholderKey) { var result = new RenderingChrome(); var wrapper = new global::Sitecore.Mvc.ExperienceEditor.Pipelines.Response.RenderPlaceholder.AddWrapper(); using (var sw = new StringWriter()) { var sb = sw.GetStringBuilder(); var args = new RenderPlaceholderArgs(placeholderKey, sw) { }; using (PlaceholderContext.Enter(new PlaceholderContext(args.PlaceholderName))) { wrapper.Process(args); result.Start = sb.ToString(); sb.Clear(); foreach (var disposable in args.Disposables) { disposable.Dispose(); } } result.End = sb.ToString(); } return(result); }
static string GetPlaceholderKey(PlaceholderContext placeholderContext) { Assert.ArgumentNotNull((object)placeholderContext, "placeholderContext"); string placeholderPath = placeholderContext.PlaceholderPath; if (placeholderPath.LastIndexOf("/") > 0) return placeholderPath; return placeholderPath.Replace("/", string.Empty); }
protected virtual IMarker GetMarker() { PlaceholderContext currentOrNull = PlaceholderContext.CurrentOrNull; if (currentOrNull == null) { return((IMarker)null); } return(new PlaceHolderMarker(currentOrNull, PageContext.Current)); }
static string GetPlaceholderKey(PlaceholderContext placeholderContext) { Assert.ArgumentNotNull((object)placeholderContext, "placeholderContext"); string placeholderPath = placeholderContext.PlaceholderPath; if (placeholderPath.LastIndexOf("/") > 0) { return(placeholderPath); } return(placeholderPath.Replace("/", string.Empty)); }
/// <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()); } } }
private RenderingChrome?GetRenderingChrome(global::Sitecore.Mvc.Presentation.Rendering rendering) { var result = new RenderingChrome(); using (var sw = new StringWriter()) using (RenderingContext.EnterContext(rendering)) using (PlaceholderContext.Enter(new PlaceholderContext("dummy"))) //todo: can a rendering chrome differ per placeholder? { var sb = sw.GetStringBuilder(); var wrapper = new global::Sitecore.Mvc.ExperienceEditor.Pipelines.Response.RenderRendering.AddWrapper(); var args = new RenderRenderingArgs(rendering, sw); wrapper.Process(args); result.Start = sb.ToString(); sb.Clear(); foreach (var disposable in args.Disposables) { disposable.Dispose(); } result.End = sb.ToString(); } return(result); }
static void Main(string[] args) { IPlaceholderContext placeholderContext = new PlaceholderContext(); IPlaceholderFactory placeholderFactory = new PlaceholderFactory(); IPlaceholderRegister placeholderRegister = new PlaceholderRegister(placeholderContext, placeholderFactory); List <User> fakeUserTable = new List <User> { new User { Id = 1, Name = "Miro", LastName = "Mirić", OIB = "12121212-1" }, new User { Id = 2, Name = "Miro2", LastName = "Mirić2", OIB = "12121212-2" }, new User { Id = 3, Name = "Miro3", LastName = "Mirić3", OIB = "12121212-3" }, new User { Id = 4, Name = "Miro4", LastName = "Mirić4", OIB = "12121212-4" }, new User { Id = 5, Name = "Miro5", LastName = "Mirić5", OIB = "12121212-5" }, }; List <Address> fakeAdressTable = new List <Address> { new Address { Id = 1, AddressName = "a1", userId = 1 }, new Address { Id = 2, AddressName = "a2", userId = 1 }, new Address { Id = 3, AddressName = "a3", userId = 2 }, new Address { Id = 4, AddressName = "a4", userId = 2 }, new Address { Id = 5, AddressName = "a5", userId = 3 }, }; //set data placeholderContext.UserId = 1; placeholderContext.Users = fakeUserTable; placeholderContext.Addresses = fakeAdressTable; //All replacing should be specified here //Problem: possibly to many data string testInput = "I am [[last_name_placeholder]], [[name_placeholder]] [[last_name_placeholder]]."; testInput = testInput.Replace("[[name_placeholder]]", placeholderRegister.GetNamePlaceholder(placeholderContext.UserId)); testInput = testInput.Replace("[[last_name_placeholder]]", placeholderRegister.GetLastNamePlaceholder(placeholderContext.UserId)); testInput = testInput.Replace("[[oib_placeholder]]", placeholderRegister.GetOIBPlaceholder(placeholderContext.UserId)); Console.WriteLine(testInput); Console.ReadKey(); }
// 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)\">""); stringWriter.Write(pageContext.Item.DisplayName); stringWriter.Write("" 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); } }
// 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)\">""); stringWriter.Write(pageContext.Item.DisplayName); stringWriter.Write("" 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); } }