Example #1
0
        /// <summary>
        /// Renders the section contents.
        /// </summary>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <param name="webPage">The web page.</param>
        /// <param name="model">The model.</param>
        public static void RenderSectionContents(this HtmlHelper htmlHelper, WebPageBase webPage, RenderPageViewModel model)
        {
            foreach (var region in model.Regions)
            {
                var contentsBuilder = new StringBuilder();
                var projections     = model.Contents.Where(c => c.RegionId == region.RegionId).OrderBy(c => c.Order).ToList();

                using (new LayoutRegionWrapper(contentsBuilder, region, model.AreRegionsEditable))
                {
                    foreach (var projection in projections)
                    {
                        // Add Html
                        using (new RegionContentWrapper(contentsBuilder, projection, model.CanManageContent && model.AreRegionsEditable))
                        {
                            var content = projection.GetHtml(htmlHelper);
                            contentsBuilder.Append(content);
                        }
                    }
                }

                var pageHtmlHelper = new PageHtmlRenderer.PageHtmlRenderer(contentsBuilder, model);
                if (model.AreRegionsEditable)
                {
                    pageHtmlHelper.ReplaceRegionRepresentationHtml();
                }
                var html = pageHtmlHelper.GetReplacedHtml().ToString();

                RenderSectionAsLayoutRegion(webPage, html, region.RegionIdentifier);
            }
        }
Example #2
0
        /// <summary>
        /// Renders page to string recursively - going deep to master pages and layouts.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="currentModel">The model.</param>
        /// <param name="pageModel">The page model.</param>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <returns>
        /// String builder with updated data
        /// </returns>
        private static StringBuilder RenderRecursively(CmsControllerBase controller, RenderPageViewModel currentModel, RenderPageViewModel pageModel, HtmlHelper htmlHelper)
        {
            if (currentModel.MasterPage != null)
            {
                var renderedMaster = RenderRecursively(controller, currentModel.MasterPage, pageModel, htmlHelper);

                var pageHtmlHelper = new PageHtmlRenderer.PageHtmlRenderer(renderedMaster, pageModel);

                foreach (var region in currentModel.Regions)
                {
                    var contentsBuilder = new StringBuilder();
                    var projections     = currentModel.Contents.Where(c => c.RegionId == region.RegionId).OrderBy(c => c.Order).ToList();

                    using (new LayoutRegionWrapper(contentsBuilder, region, currentModel.AreRegionsEditable))
                    {
                        foreach (var projection in projections)
                        {
                            // Add Html
                            using (new RegionContentWrapper(contentsBuilder, projection, currentModel.CanManageContent && currentModel.AreRegionsEditable))
                            {
                                // Pass current model as view data model
                                htmlHelper.ViewData.Model = pageModel;

                                var content = projection.GetHtml(htmlHelper);
                                contentsBuilder.Append(content);
                            }
                        }
                    }

                    // Insert region to master page
                    var html = contentsBuilder.ToString();
                    pageHtmlHelper.ReplaceRegionHtml(region.RegionIdentifier, html);
                }

                if (currentModel.AreRegionsEditable)
                {
                    pageHtmlHelper.ReplaceRegionRepresentationHtml();
                }
                renderedMaster = pageHtmlHelper.GetReplacedHtml();

                return(renderedMaster);
            }

            var newModel = currentModel.Clone();

            newModel.Id            = pageModel.Id;
            newModel.PageUrl       = pageModel.PageUrl;
            newModel.Title         = pageModel.Title;
            newModel.MetaTitle     = pageModel.MetaTitle;
            newModel.RenderingPage = pageModel;
            newModel.Metadata      = pageModel.Metadata;
            newModel.IsReadOnly    = pageModel.IsReadOnly;

            PopulateCollections(newModel, pageModel);

            var renderedView = RenderViewToString(controller, "~/Areas/bcms-Root/Views/Cms/Index.cshtml", newModel);

            return(new StringBuilder(renderedView));
        }
        /// <summary>
        /// Renders page to string recursively - going deep to master pages and layouts.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="currentModel">The model.</param>
        /// <param name="pageModel">The page model.</param>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <returns>
        /// String builder with updated data
        /// </returns>
        private static StringBuilder RenderRecursively(CmsControllerBase controller, RenderPageViewModel currentModel, RenderPageViewModel pageModel, HtmlHelper htmlHelper)
        {
            if (currentModel.MasterPage != null)
            {
                var renderedMaster = RenderRecursively(controller, currentModel.MasterPage, pageModel, htmlHelper);

                var pageHtmlHelper = new PageHtmlRenderer.PageHtmlRenderer(renderedMaster, pageModel);
                var contentHtmlHelper = new ChildContentRenderHelper(htmlHelper);

                foreach (var region in currentModel.Regions)
                {
                    var contentsBuilder = new StringBuilder();
                    var projections = currentModel.Contents.Where(c => c.RegionId == region.RegionId).OrderBy(c => c.Order).ToList();

                    using (new LayoutRegionWrapper(contentsBuilder, region, currentModel.AreRegionsEditable))
                    {
                        foreach (var projection in projections)
                        {
                            // Add Html
                            using (new RegionContentWrapper(contentsBuilder, projection, currentModel.CanManageContent && currentModel.AreRegionsEditable))
                            {
                                // Pass current model as view data model
                                htmlHelper.ViewData.Model = pageModel;

                                contentsBuilder = contentHtmlHelper.AppendHtml(contentsBuilder, projection);
                            }
                        }
                    }

                    // Insert region to master page
                    var html = contentsBuilder.ToString();
                    pageHtmlHelper.ReplaceRegionHtml(region.RegionIdentifier, html);
                }

                if (currentModel.AreRegionsEditable)
                {
                    pageHtmlHelper.ReplaceRegionRepresentationHtml();
                }
                renderedMaster = pageHtmlHelper.GetReplacedHtml();

                return renderedMaster;
            }

            var newModel = currentModel.Clone();
            newModel.Id = pageModel.Id;
            newModel.PageUrl = pageModel.PageUrl;
            newModel.Title = pageModel.Title;
            newModel.MetaTitle = pageModel.MetaTitle;
            newModel.MetaKeywords = pageModel.MetaKeywords;
            newModel.MetaDescription = pageModel.MetaDescription;
            newModel.RenderingPage = pageModel;
            newModel.Metadata = pageModel.Metadata;
            newModel.IsReadOnly = pageModel.IsReadOnly;
            newModel.CreatedOn = pageModel.CreatedOn;
            newModel.ModifiedOn = pageModel.ModifiedOn;
            newModel.CreatedByUser = pageModel.CreatedByUser;
            newModel.ModifiedByUser = pageModel.ModifiedByUser;

            PopulateCollections(newModel, pageModel);

            var renderedView = RenderViewToString(controller, "~/Areas/bcms-Root/Views/Cms/Index.cshtml", newModel);
            return new StringBuilder(renderedView);
        }