protected override void BeforeRenderContentAreaItemStartTag(TagBuilder tagBuilder, ContentAreaItem contentAreaItem) { var highLight = HttpContext.Current.Request[Constants.HighlightQueryStringKey]; if (highLight != null && highLight.Equals(contentAreaItem.GetContent().ContentGuid.ToString())) tagBuilder.AddCssClass(HighlightedCssClass); base.BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem); }
protected override void RenderContentAreaItem( HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, string templateTag, string htmlTag, string cssClass) { var content = contentAreaItem.GetContent(ContentRepository); if (content == null) { return; } var serialisedContent = EpiServerDonutHelper.SerializeBlockContentReference(content); using (var textWriter = new StringWriter()) { var cutomHtmlHelper = EpiServerDonutHelper.CreateHtmlHelper(htmlHelper.ViewContext.Controller, textWriter); EpiServerDonutHelper.RenderContentData(cutomHtmlHelper, content, string.Empty); var tagBuilder = CreateContentAreaSeperatorHtmlTags(contentAreaItem, htmlTag, cssClass); var epiServerHtml = EpiServerDonutHelper.CreateContentAreaDonutTag(tagBuilder, serialisedContent, textWriter.ToString()); htmlHelper.RenderXhtmlString(new XhtmlString(epiServerHtml)); } }
public ActionResult Item(SyndicationFeedPageType currentPage, int?contentId) { if (!contentId.HasValue) { return(HttpNotFound("No content Id specified")); } var contentReference = ContentReference.Parse(contentId.Value.ToString()); var referencedContent = _feedContentResolver.GetContentReferences(currentPage); if (!referencedContent.Contains(contentReference)) { return(HttpNotFound("Content Id not exposed in this feed")); } var contentArea = new ContentArea(); var item = new ContentAreaItem { ContentLink = contentReference }; contentArea.Items.Add(item); var contentItem = _contentLoader.Get <IContent>(contentReference); var model = new ContentHolderModel { Tag = currentPage.BlockRenderingTag, ContentArea = contentArea, Content = contentItem }; return(View("~/modules/Chief2moro.SyndicationFeeds/Views/Item.cshtml", model)); }
protected override string GetContentAreaItemCssClass(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem) { var tag = GetContentAreaItemTemplateTag(htmlHelper, contentAreaItem); return ($"block {GetTypeSpecificCssClasses(contentAreaItem, ContentRepository)} {GetCssClassForTag(tag)} {tag}"); }
public IContent Get(ContentAreaItem contentAreaItem) { if ((PageEditing.PageIsInEditMode || _contextModeResolver.CurrentMode == ContextMode.Preview) && ContentDraftView.IsInContentDraftViewMode) { var languageResolver = ServiceLocator.Current.GetInstance <LanguageResolver>(); var commonDraft = ServiceLocator.Current.GetInstance <IContentVersionRepository>() .LoadCommonDraft(contentAreaItem.ContentLink, languageResolver.GetPreferredCulture().Name); if (commonDraft != null) { var contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>(); var content = contentLoader.Get <IContent>(commonDraft.ContentLink); if (content.IsPublished()) { var defaultContent = _defaultContentAreaLoader.Get(contentAreaItem); return(defaultContent); } if (!contentAreaItem.IsReadOnly) { contentAreaItem.ContentLink = commonDraft.ContentLink; } return(content); } } return(_defaultContentAreaLoader.Get(contentAreaItem)); }
protected override string GetContentAreaItemCssClass(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem) { var childrenCssClass = htmlHelper.ViewData["ChildrenCssClass"]; if(childrenCssClass != null) { return childrenCssClass.ToString(); } var tag = GetContentAreaItemTemplateTag(htmlHelper, contentAreaItem); var content = contentAreaItem.GetContent(ContentRepository); if(content != null) { if (tag == null ) { // Let block decide what to use as default if not // specified on the content area itself tag = GetDefaultDisplayOption(content); if (tag == null) { // Default is always the smalles one we've got tag = WebGlobal.ContentAreaTags.OneThirdWidth; } } htmlHelper.ViewContext.ViewData["Tag"] = tag; return string.Format("block {0} {1} {2}", GetTypeSpecificCssClasses(content), GetCssClassForTag(tag), tag); } else { return WebGlobal.ContentAreaTags.NoRenderer; } }
internal string GetItemCssClass(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem) { var tag = GetContentAreaItemTemplateTag(htmlHelper, contentAreaItem); var baseClasses = base.GetContentAreaItemCssClass(htmlHelper, contentAreaItem); return($"block {GetTypeSpecificCssClasses(contentAreaItem, ContentRepository)} {GetCssClassesForTag(contentAreaItem, tag)} {tag} {baseClasses}"); }
internal string GetCssClassesForTag(ContentAreaItem contentAreaItem, string tagName) { if (string.IsNullOrWhiteSpace(tagName)) { tagName = ContentAreaTags.FullWidth; } var extraTagInfo = string.Empty; // try to find default display option only if CA was rendered with tag // passed in tag is equal with tag used to render content area - block does not have any display option set explicitly if (!string.IsNullOrEmpty(ContentAreaTag) && tagName.Equals(ContentAreaTag)) { // we also might have defined default display options for particular CA tag (Html.PropertyFor(m => m.ContentArea, new { tag = ... })) var curentContent = GetCurrentContent(contentAreaItem); var defaultAttribute = curentContent?.GetOriginalType() .GetCustomAttributes <DefaultDisplayOptionForTagAttribute>() .FirstOrDefault(a => a.Tag == ContentAreaTag); if (defaultAttribute != null) { tagName = defaultAttribute.DisplayOption; extraTagInfo = tagName; } } var fallback = _fallbacks.FirstOrDefault(f => f.Tag == tagName) ?? _fallbacks.FirstOrDefault(f => f.Tag == ContentAreaTags.FullWidth); if (fallback == null) { return(string.Empty); } return($"{GetCssClassesForItem(fallback)}{(string.IsNullOrEmpty(extraTagInfo) ? string.Empty : $" {extraTagInfo}")}");
private static void RenderAreaItem( HtmlHelper html, ContentAreaItem contentAreaItem, BootstrapAwareContentAreaRenderer renderer, IFormElement element) { if (contentAreaItem != null) { var cssClasses = renderer.GetItemCssClass(html, contentAreaItem); html.ViewContext.Writer.Write($"<div class=\"{cssClasses}\">"); } var sourceContent = element.SourceContent; if (sourceContent != null && !sourceContent.IsDeleted) { if (sourceContent is ISubmissionAwareElement) { var contentData = (sourceContent as IReadOnly).CreateWritableClone() as IContent; (contentData as ISubmissionAwareElement).FormSubmissionId = (string)html.ViewBag.FormSubmissionId; html.RenderContentData(contentData, false); } else { html.RenderContentData(sourceContent, false); } } if (contentAreaItem != null) { html.ViewContext.Writer.Write("</div>"); } }
protected override void RenderContentAreaItem(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, string templateTag, string htmlTag, string cssClass) { _renderingContext.BeginRenderingItem(contentAreaItem, _contentAreaLoader.Get(contentAreaItem), _contentAreaLoader.LoadDisplayOption(contentAreaItem)); base.RenderContentAreaItem(htmlHelper, contentAreaItem, templateTag, htmlTag, cssClass); _renderingContext.FinishRenderingItem(); }
public static string GetNewsletterColumns(this HtmlHelper html, ContentAreaItem content, out int columns) { var newsletterColumn = NewsletterColumns.twelve; DisplayOption displayOption = content.LoadDisplayOption(); if (displayOption != null) { switch (displayOption.Tag) { case WebGlobal.ContentAreaTags.FullWidth: newsletterColumn = NewsletterColumns.twelve; break; case WebGlobal.ContentAreaTags.TwoThirdsWidth: newsletterColumn = NewsletterColumns.eight; break; case WebGlobal.ContentAreaTags.HalfWidth: newsletterColumn = NewsletterColumns.six; break; case WebGlobal.ContentAreaTags.OneThirdWidth: newsletterColumn = NewsletterColumns.four; break; case WebGlobal.ContentAreaTags.Slider: newsletterColumn = NewsletterColumns.twelve; break; } } columns = (int)newsletterColumn; return(newsletterColumn.ToString()); }
public IContent Get(ContentAreaItem contentAreaItem) { if (!ExternalReview.IsInExternalReviewContext) { return(_defaultContentAreaLoader.Get(contentAreaItem)); } // load common draft instead of published version var commonDraft = _contentVersionRepository.LoadCommonDraft(contentAreaItem.ContentLink, _languageResolver.GetPreferredCulture().Name); if (commonDraft != null) { var content = _contentLoader.Get <IContent>(commonDraft.ContentLink); if (content.IsPublished()) { // for published version return the original method result var defaultContent = _defaultContentAreaLoader.Get(contentAreaItem); return(defaultContent); } contentAreaItem.ContentLink = commonDraft.ContentLink; return(content); } return(_defaultContentAreaLoader.Get(contentAreaItem)); }
private void ProcessItemContent(string contentItemContent, ContentAreaItem contentAreaItem, IContent content, HtmlHelper htmlHelper, TextWriter originalWriter) { HtmlNode blockContentNode = null; var shouldStop = CallbackOnItemNode(contentItemContent, contentAreaItem, content, ref blockContentNode); if (shouldStop) { return; } shouldStop = RenderItemContainer(contentItemContent, htmlHelper, originalWriter, ref blockContentNode); if (shouldStop) { return; } shouldStop = ControlItemVisibility(contentItemContent, content, originalWriter, ref blockContentNode); if (shouldStop) { return; } // finally we just render whole body if (blockContentNode == null) { PrepareNodeElement(ref blockContentNode, contentItemContent); } originalWriter.Write(blockContentNode.OuterHtml); }
protected override void RenderContentAreaItem(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, string templateTag, string htmlTag, string cssClass) { ViewContext viewContext = htmlHelper.ViewContext; IContent content = contentAreaItem.GetContent(this._contentRepository); if (content != null) { using (new ContentAreaContext(viewContext.RequestContext, content.ContentLink)) { TemplateModel templateModel = this.ResolveTemplate(htmlHelper, content, templateTag); if ((templateModel != null) || this.IsInEditMode(htmlHelper)) { TagBuilder tagBuilder = new TagBuilder(htmlTag); SliderItemSettings itemSettings = viewContext.ViewData["sliderSettings"] as SliderItemSettings; MergeSettings(tagBuilder, itemSettings); if (contentAreaItem.RenderSettings.ContainsKey("sliderSettings")) { itemSettings = contentAreaItem.RenderSettings["sliderSettings"] as SliderItemSettings; MergeSettings(tagBuilder, itemSettings); } // We can override settings per content item tagBuilder.MergeAttributes(contentAreaItem.RenderSettings); BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem); viewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag)); htmlHelper.RenderContentData(content, true, templateModel, _contentRenderer); viewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.EndTag)); } } } }
public IContent Get(ContentAreaItem contentAreaItem) { if (!ExternalReview.IsInExternalReviewContext) { return(_defaultContentAreaLoader.Get(contentAreaItem)); } var referenceToLoad = _reviewsContentLoader.LoadUnpublishedVersion(contentAreaItem.ContentLink); if (referenceToLoad == null) { // fallback to default implementation if there is no common draft in a given language return(_defaultContentAreaLoader.Get(contentAreaItem)); } var content = _contentLoader.Get <IContent>(referenceToLoad); if (_reviewsContentLoader.HasExpired(content as IVersionable)) { return(null); } if (content.IsPublished()) { // for published version return the original method result return(_defaultContentAreaLoader.Get(contentAreaItem)); } if (!contentAreaItem.IsReadOnly) { contentAreaItem.ContentLink = referenceToLoad; } return(content); }
internal string GetItemCssClass(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem) { var tag = GetContentAreaItemTemplateTag(htmlHelper, contentAreaItem); var baseClasses = base.GetContentAreaItemCssClass(htmlHelper, contentAreaItem); return($"block {GetTypeSpecificCssClasses(contentAreaItem)}{(!string.IsNullOrEmpty(GetCssClassesForTag(contentAreaItem, tag)) ? " " +GetCssClassesForTag(contentAreaItem, tag) : "")}{(!string.IsNullOrEmpty(tag) ? " " + tag : "")}{(!string.IsNullOrEmpty(baseClasses) ? baseClasses : "")}"); }
protected override string GetContentAreaItemCssClass(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem) { var tag = GetContentAreaItemTemplateTag(htmlHelper, contentAreaItem); var content = contentAreaItem.GetContent(ContentRepository); if (content != null) { if (tag == null) { // Let block decide what to use as default if not // specified on the content area itself tag = GetDefaultDisplayOption(content); if (tag == null) { // Default is always the smalles one we've got tag = WebGlobal.ContentAreaTags.OneThirdWidth; } } htmlHelper.ViewContext.ViewData["Tag"] = tag; return(string.Format("block {0} {1} {2}", GetTypeSpecificCssClasses(content), GetCssClassForTag(tag), tag)); } else { return(WebGlobal.ContentAreaTags.NoRenderer); } }
protected override void RenderContentAreaItem( HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, string templateTag, string htmlTag, string cssClass) { var renderSettings = new Dictionary <string, object> { ["childrencustomtagname"] = htmlTag, ["childrencssclass"] = cssClass, ["tag"] = templateTag }; renderSettings = contentAreaItem.RenderSettings.Concat( from r in renderSettings where !contentAreaItem.RenderSettings.ContainsKey(r.Key) select r).ToDictionary(r => r.Key, r => r.Value); htmlHelper.ViewBag.RenderSettings = renderSettings; var content = _contentAreaLoader.Get(contentAreaItem); if (content == null) { return; } bool isInEditMode = IsInEditMode(htmlHelper); using (new ContentAreaContext(htmlHelper.ViewContext.RequestContext, content.ContentLink)) { var templateModel = ResolveTemplate(htmlHelper, content, templateTag); if (templateModel != null || isInEditMode) { bool renderWrappingElement = ShouldRenderWrappingElementForContentAreaItem(htmlHelper); // The code for this method has been c/p from EPiServer.Web.Mvc.Html.ContentAreaRenderer. // The only difference is this if/else block. if (isInEditMode || renderWrappingElement) { var tagBuilder = new TagBuilder(htmlTag); AddNonEmptyCssClass(tagBuilder, cssClass); tagBuilder.MergeAttributes(_attributeAssembler.GetAttributes( contentAreaItem, isInEditMode, templateModel != null)); BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem); htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag)); htmlHelper.RenderContentData(content, true, templateModel, _contentRenderer); htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.EndTag)); } else { // This is the extra code: don't render wrapping elements in view mode htmlHelper.RenderContentData(content, true, templateModel, _contentRenderer); } } } }
protected override void RenderContentAreaItem(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, string templateTag, string htmlTag, string cssClass) { var dictionary = new Dictionary <string, object>(); dictionary["childrencustomtagname"] = htmlTag; dictionary["childrencssclass"] = cssClass; dictionary["tag"] = templateTag; dictionary = contentAreaItem.RenderSettings.Concat( ( from r in dictionary where !contentAreaItem.RenderSettings.ContainsKey(r.Key) select r ) ).ToDictionary(r => r.Key, r => r.Value); htmlHelper.ViewBag.RenderSettings = dictionary; var content = contentAreaItem.GetContent(); if (content != null) { try { using (new ContentAreaContext(htmlHelper.ViewContext.RequestContext, content.ContentLink)) { var templateModel = ResolveTemplate(htmlHelper, content, templateTag); if ((templateModel != null) || IsInEditMode(htmlHelper)) { if (IsInEditMode(htmlHelper)) { var tagBuilder = new TagBuilder(htmlTag); AddNonEmptyCssClass(tagBuilder, cssClass); tagBuilder.MergeAttributes <string, string>( _attributeAssembler.GetAttributes( contentAreaItem, IsInEditMode(htmlHelper), (bool)(templateModel != null))); BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem); htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag)); htmlHelper.RenderContentData(content, true, templateModel, _contentRenderer); htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.EndTag)); } else { htmlHelper.RenderContentData(content, true, templateModel, _contentRenderer); } } } } catch (Exception e) { _logger.Error("[CustomContentAreaRenderer.RenderContentAreaItem] exception", e); if (PageEditing.PageIsInEditMode) { var errorModel = new ContentRenderingErrorModel(content, e); htmlHelper.RenderPartial("TemplateError", errorModel); } } } }
private TagBuilder CreateContentAreaSeperatorHtmlTags(ContentAreaItem contentAreaItem, string htmlTag, string cssClass) { var tagBuilder = new TagBuilder(htmlTag); AddNonEmptyCssClass(tagBuilder, cssClass); BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem); return(tagBuilder); }
public static T GetBlock <T>(this ContentAreaItem contentAreaItem) where T : BlockData { if (contentAreaItem == null) { return(null); } return(ContentLoader.Value.Get <IContentData>(contentAreaItem.ContentLink) as T); }
protected virtual IContent GetCurrentContent(ContentAreaItem contentAreaItem) { if (_currentContent == null || !_currentContent.ContentLink.CompareToIgnoreWorkID(contentAreaItem.ContentLink)) { _currentContent = contentAreaItem.GetContent(); } return(_currentContent); }
protected override string GetContentAreaItemCssClass(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem) { var tag = GetContentAreaItemTemplateTag(htmlHelper, contentAreaItem); var baseClasses = base.GetContentAreaItemCssClass(htmlHelper, contentAreaItem); return(string.Format("block {0} {1} {2} {3}", GetTypeSpecificCssClasses(contentAreaItem, ContentRepository), GetCssClassesForTag(tag), tag, baseClasses)); }
protected virtual string GetContentAreaItemCssClass(HtmlHelper html, ContentAreaItem contentAreaItem, string templateTag) { var baseClass = base.GetContentAreaItemCssClass(html, contentAreaItem); if (!string.IsNullOrEmpty(baseClass)) { return(baseClass); } return(string.Format("block {0}", templateTag)); }
public IContent Get(ContentAreaItem contentAreaItem) { if (!PageEditing.PageIsInEditMode) { return(_defaultContentAreaLoader.Get(contentAreaItem)); } var maxContentDate = MaxContentDate; if (maxContentDate.HasValue == false) { return(_defaultContentAreaLoader.Get(contentAreaItem)); } var languageResolver = ServiceLocator.Current.GetInstance <LanguageResolver>(); var contentVersionRepository = ServiceLocator.Current.GetInstance <IContentVersionRepository>(); var language = languageResolver.GetPreferredCulture().Name; var contentVersions = contentVersionRepository.List(contentAreaItem.ContentLink.ToReferenceWithoutVersion(), language).ToList(); if (contentVersions.Count < 2) { return(_defaultContentAreaLoader.Get(contentAreaItem)); } var version = contentVersions.Where(x => x.Saved < maxContentDate).OrderByDescending(x => x.Saved).FirstOrDefault(); var contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>(); if (version == null) { var oldestVersion = contentVersions.OrderBy(x => x.Saved).First(); if (maxContentDate.Value <= oldestVersion.Saved) { var oldestContent = contentLoader.Get <IContent>(oldestVersion.ContentLink); contentAreaItem.ContentLink = oldestVersion.ContentLink; return(oldestContent); } var newestVersion = contentVersions.OrderByDescending(x => x.Saved).First(); if (maxContentDate.Value <= newestVersion.Saved) { var newestContent = contentLoader.Get <IContent>(newestVersion.ContentLink); contentAreaItem.ContentLink = newestVersion.ContentLink; return(newestContent); } return(_defaultContentAreaLoader.Get(contentAreaItem)); } var content = contentLoader.Get <IContent>(version.ContentLink); contentAreaItem.ContentLink = version.ContentLink; return(content); }
protected override string GetContentAreaItemCssClass(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem) { var tag = GetContentAreaItemTemplateTag(htmlHelper, contentAreaItem); var baseClasses = base.GetContentAreaItemCssClass(htmlHelper, contentAreaItem); return string.Format("block {0} {1} {2} {3}", GetTypeSpecificCssClasses(contentAreaItem, ContentRepository), GetCssClassesForTag(tag), tag, baseClasses); }
private static string GetTypeSpecificCssClasses(ContentAreaItem contentAreaItem, IContentRepository contentRepository) { var content = contentAreaItem.GetContent(); var cssClass = content == null ? String.Empty : content.GetOriginalType().Name.ToLowerInvariant(); if (content is ICustomCssInContentArea customClassContent && !string.IsNullOrWhiteSpace(customClassContent.ContentAreaCssClass)) { cssClass += string.Format(" {0}", customClassContent.ContentAreaCssClass); } return(cssClass); }
protected override string GetContentAreaItemCssClass(IHtmlHelper htmlHelper, ContentAreaItem contentAreaItem) { var baseClass = base.GetContentAreaItemCssClass(htmlHelper, contentAreaItem); var tag = GetContentAreaItemTemplateTag(htmlHelper, contentAreaItem); if (!string.IsNullOrEmpty(baseClass)) { return(baseClass); } return($"block {tag} {GetCssClassForTag(tag)}"); }
public IContent Get(ContentAreaItem contentAreaItem) { if (!ExternalReview.IsInExternalReviewContext) { return(_defaultContentAreaLoader.Get(contentAreaItem)); } ContentReference referenceToLoad; if (ExternalReview.ProjectId.HasValue) { // load version from project referenceToLoad = _projectContentResolver.GetProjectReference(contentAreaItem.ContentLink, ExternalReview.ProjectId.Value); } else { // load common draft instead of published version var loadCommonDraft = _contentVersionRepository.LoadCommonDraft(contentAreaItem.ContentLink, _languageResolver.GetPreferredCulture().Name); if (loadCommonDraft == null) { // fallback to default implementation if there is no common draft in a given language return(_defaultContentAreaLoader.Get(contentAreaItem)); } referenceToLoad = loadCommonDraft.ContentLink; } if (referenceToLoad != null) { var content = _contentLoader.Get <IContent>(referenceToLoad); if (HasExpired(content as IVersionable)) { return(null); } if (content.IsPublished()) { // for published version return the original method result return(_defaultContentAreaLoader.Get(contentAreaItem)); } if (!contentAreaItem.IsReadOnly) { contentAreaItem.ContentLink = referenceToLoad; } return(content); } return(_defaultContentAreaLoader.Get(contentAreaItem)); }
private static string GetTypeSpecificCssClasses(ContentAreaItem contentAreaItem, IContentRepository contentRepository) { var content = contentAreaItem.GetContent(contentRepository); var cssClass = content == null ? String.Empty : content.GetOriginalType().Name.ToLowerInvariant(); var customClassContent = content as ICustomCssInContentArea; if (customClassContent != null && !string.IsNullOrWhiteSpace(customClassContent.ContentAreaCssClass)) { cssClass += string.Format("{0}", customClassContent.ContentAreaCssClass); } return cssClass; }
public static TType Get <TType>(this ContentAreaItem contentAreaItem) where TType : IContentData { if (contentAreaItem is null) { return(default(TType)); } var content = _contentLoader.Get <IContentData>(contentAreaItem.ContentLink); if (content is TType rtnContent) { return(rtnContent); } return(default(TType)); }
private NewsCardDto Map(ContentAreaItem item) { if (!_contentLoader.TryGet(item.ContentLink, out IHasCardRendering cardRendering)) { return(null); } return(new NewsCardDto { Title = cardRendering.Title, ImageUrl = _urlResolver.GetUrl(cardRendering.Image), Author = cardRendering.Author, LinkUrl = _urlResolver.GetUrl(cardRendering.ContentLink) }); }
public ContentArea CreateRelatedProductsContentArea(EntryContentBase catalogContent, string associationType) { IEnumerable <Association> associations = LinksRepository.GetAssociations(catalogContent.ContentLink); ContentArea relatedEntriesCA = new ContentArea(); List <EntryContentBase> relatedEntires = Enumerable.Where(associations, p => p.Group.Name.Equals(associationType)) .Select(a => ContentLoader.Get <EntryContentBase>(a.Target)).ToList(); foreach (var relatedEntire in relatedEntires) { ContentAreaItem caItem = new ContentAreaItem(); caItem.ContentLink = relatedEntire.ContentLink; relatedEntriesCA.Items.Add(caItem); } return(relatedEntriesCA); }
private static string GetTypeSpecificCssClasses(ContentAreaItem contentAreaItem, IContentLoader contentLoader) { var content = contentAreaItem.GetContent(contentLoader); var cssClass = content == null ? string.Empty : content.GetOriginalType().Name.ToLowerInvariant(); // ReSharper disable once SuspiciousTypeConversion.Global var customClassContent = content as ICustomCssInContentArea; if (customClassContent != null && !string.IsNullOrWhiteSpace(customClassContent.ContentAreaCssClass)) { cssClass += string.Format(" {0}", customClassContent.ContentAreaCssClass); } return(cssClass); }
public ContentAreaItemContext(ViewDataDictionary viewData, ContentAreaItem contentAreaItem) { _viewData = viewData; var displayOption = contentAreaItem.LoadDisplayOption() ?? new DisplayOption { Id = Guid.NewGuid().ToString(), Name = "Unknown" }; if (!_viewData.ContainsKey(Constants.CurrentDisplayOptionKey)) { _viewData.Add(Constants.CurrentDisplayOptionKey, displayOption); } else { _viewData[Constants.CurrentDisplayOptionKey] = displayOption; } }
private static string GetTypeSpecificCssClasses(ContentAreaItem contentAreaItem, IContentLoader contentLoader) { var content = contentAreaItem.GetContent(contentLoader); var cssClass = content == null ? string.Empty : content.GetOriginalType().Name.ToLowerInvariant(); // ReSharper disable once SuspiciousTypeConversion.Global var customClassContent = content as ICustomCssInContentArea; if (customClassContent != null && !string.IsNullOrWhiteSpace(customClassContent.ContentAreaCssClass)) { cssClass += string.Format(" {0}", customClassContent.ContentAreaCssClass); } return cssClass; }
protected override void RenderContentAreaItem( HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, string templateTag, string htmlTag, string cssClass) { var originalWriter = htmlHelper.ViewContext.Writer; var tempWriter = new StringWriter(); htmlHelper.ViewContext.Writer = tempWriter; try { var content = contentAreaItem.GetContent(ContentRepository); base.RenderContentAreaItem(htmlHelper, contentAreaItem, templateTag, htmlTag, cssClass); var contentItemContent = tempWriter.ToString(); if (IsInEditMode(htmlHelper)) { // we need to render block if we are in Edit mode originalWriter.Write(contentItemContent); } else { var doc = new HtmlDocument(); doc.Load(new StringReader(contentItemContent)); var blockContentNode = doc.DocumentNode.ChildNodes.FirstOrDefault(); if (blockContentNode == null) { return; } // pass node to callback for some fancy modifications (if any) _elementStartTagRenderCallback?.Invoke(blockContentNode, contentAreaItem, content); if (!string.IsNullOrEmpty(blockContentNode.InnerHtml.Trim(null))) { var renderItemContainer = GetFlagValueFromViewData(htmlHelper, "hasitemcontainer"); if (!renderItemContainer.HasValue || renderItemContainer.Value) { originalWriter.Write(blockContentNode.OuterHtml); } else { originalWriter.Write(blockContentNode.InnerHtml); } } else { // ReSharper disable once SuspiciousTypeConversion.Global var visibilityControlledContent = content as IControlVisibility; if ((visibilityControlledContent == null) || !visibilityControlledContent.HideIfEmpty) { originalWriter.Write(blockContentNode.OuterHtml); } } } } finally { // restore original writer to proceed further with rendering pipeline htmlHelper.ViewContext.Writer = originalWriter; } }
internal string GetCssClassesForTag(ContentAreaItem contentAreaItem, string tagName) { if(string.IsNullOrWhiteSpace(tagName)) { tagName = ContentAreaTags.FullWidth; } var extraTagInfo = string.Empty; // try to find default display option only if CA was rendered with tag // passed in tag is equal with tag used to render content area - block does not have any display option set explicitly if(!string.IsNullOrEmpty(ContentAreaTag) && tagName.Equals(ContentAreaTag)) { // we also might have defined default display options for particular CA tag (Html.PropertyFor(m => m.ContentArea, new { tag = ... })) var curentContent = GetCurrentContent(contentAreaItem); var defaultAttribute = curentContent?.GetOriginalType() .GetCustomAttributes<DefaultDisplayOptionForTagAttribute>() .FirstOrDefault(a => a.Tag == ContentAreaTag); if(defaultAttribute != null) { tagName = defaultAttribute.DisplayOption; extraTagInfo = tagName; } } var fallback = _fallbacks.FirstOrDefault(f => f.Tag == tagName) ?? _fallbacks.FirstOrDefault(f => f.Tag == ContentAreaTags.FullWidth); if(fallback == null) { return string.Empty; } return $"{GetCssClassesForItem(fallback)}{(string.IsNullOrEmpty(extraTagInfo) ? string.Empty : $" {extraTagInfo}")}";