Example #1
0
        /// <summary>
        /// Loads the containers for the given page and caches it if specified
        /// </summary>
        /// <param name="pageId">The page id</param>
        /// <param name="cacheForRequestLife">Whether to cache for the life of the request</param>
        protected void LoadPageContainers(int pageId, bool cacheForRequestLife)
        {
            string cacheId = "wbPageContainers_" + pageId.ToString();

            if (cacheForRequestLife && CacheHelper.Exists(cacheId))
            {
                //load from cache
                var containerProvider = CacheHelper.Get <ContainerProvider>(cacheId);
                containers = containerProvider.containers;
            }
            else
            {
                //load from Umbraco
                DynamicPublishedContent content = PublishedContentProvider.Load(pageId);

                if (content == null)
                {
                    return;
                }

                string json = content.GetPropertyValue("webBlocks");
                if (!string.IsNullOrEmpty(json))
                {
                    LoadContainersFromJson(json, cacheForRequestLife, pageId.ToString());
                }
            }
        }
        public ActionResult RenderBlock()
        {
            if (umbraco.BusinessLogic.User.GetCurrent() == null)
            {
                throw new HttpException(401, "Unauthorized");
            }

            WebBlocksUtility.IsInBuilder = true;

            WebBlocksAPI blockInstanceApi = new WebBlocksAPI();

            blockInstanceApi.BlockElement    = "div";
            blockInstanceApi.BlockAttributes = new Dictionary <string, string>();
            blockInstanceApi.CssClasses      = new List <string>();

            int pageId  = int.Parse(Request.QueryString["pageId"]);
            int blockId = int.Parse(Request.QueryString["blockId"]);

            WebBlocksUtility.CurrentPageNodeId            = pageId;
            WebBlocksUtility.CurrentPageContent           = PublishedContentProvider.Load(pageId);
            WebBlocksUtility.CurrentBlockContent          = PublishedContentProvider.Load(blockId);
            WebBlocksUtility.CurrentPageIPublishedContent = new UmbracoHelper(UmbracoContext.Current).TypedContent(pageId);

            return(PartialView("BlockPreviewRender"));
        }
 /// <summary>
 /// Initialises Web Blocks with the current page
 /// </summary>
 public static void InitWebBlocks()
 {
     if (WebBlocksUtility.CurrentPageContent == null)
     {
         WebBlocksUtility.CurrentPageNodeId            = UmbracoContext.Current.PageId ?? 0;
         WebBlocksUtility.CurrentPageContent           = PublishedContentProvider.Load(UmbracoContext.Current.PageId ?? 0);
         WebBlocksUtility.CurrentPageIPublishedContent = new UmbracoHelper(UmbracoContext.Current).TypedContent(UmbracoContext.Current.PageId);
     }
 }