Ejemplo n.º 1
0
        public IHtmlString RenderBlock(IContentBlockViewModel contentBlockViewModel, HtmlHelper htmlHelper)
        {
            if (contentBlockViewModel == null)
            {
                return(MvcHtmlString.Empty);
            }

            string viewPath = GetViewPath(contentBlockViewModel.DefinitionId, contentBlockViewModel.LayoutId);

            if (string.IsNullOrEmpty(viewPath))
            {
                return(MvcHtmlString.Empty);
            }

            IHtmlString contentBlockHtml = htmlHelper.Partial(viewPath, contentBlockViewModel);

            if (!_isPreview)
            {
                return(contentBlockHtml);
            }
            else
            {
                // Preview mode: add block id for scroll synchronisation
                string blockIdAnchor = $"<a id=\"{contentBlockViewModel.Id}\" class=\"perplex-content-blocks-preview-anchor\"></a>";
                return(new MvcHtmlString(blockIdAnchor + contentBlockHtml));
            }
        }
        /// <summary>
        /// Renders a single Content Block
        /// </summary>
        /// <param name="html">HtmlHelper</param>
        /// <param name="contentBlock">Content Block to render</param>
        /// <returns></returns>
        public static IHtmlString RenderContentBlock(this HtmlHelper html, IContentBlockViewModel contentBlock)
        {
            if (contentBlock == null)
            {
                return(MvcHtmlString.Empty);
            }

            var renderer = Current.Factory.GetInstance <IContentBlockRenderer>();

            return(renderer.RenderBlock(contentBlock, html));
        }