public GetActiveContent ( int blockId, string entityValue ) : HtmlContent | ||
blockId | int | A |
entityValue | string | A |
return | HtmlContent |
/// <summary> /// Shows the view. /// </summary> protected void ShowView() { mdEdit.Hide(); pnlEditModel.Visible = false; upnlHtmlContent.Update(); // prevent htmlEditor from using viewstate when not needed pnlEdit.EnableViewState = false; pnlEdit.Visible = false; pnlVersionGrid.Visible = false; string entityValue = EntityValue(); string html = string.Empty; string cachedContent = HtmlContentService.GetCachedContent( this.BlockId, entityValue ); // if content not cached load it from DB if ( cachedContent == null ) { using ( var rockContext = new RockContext() ) { var htmlContentService = new HtmlContentService( rockContext ); HtmlContent content = htmlContentService.GetActiveContent( this.BlockId, entityValue ); if ( content != null ) { bool enableDebug = GetAttributeValue( "EnableDebug" ).AsBoolean(); if ( content.Content.HasMergeFields() || enableDebug ) { var mergeFields = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields( CurrentPerson ); if ( CurrentPerson != null ) { // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line mergeFields.Add( "Person", CurrentPerson ); mergeFields.Add( "CurrentPerson", CurrentPerson ); } mergeFields.Add( "Campuses", CampusCache.All() ); mergeFields.Add( "PageParameter", PageParameters() ); var contextObjects = new Dictionary<string, object>(); foreach ( var contextEntityType in RockPage.GetContextEntityTypes() ) { var contextEntity = RockPage.GetCurrentContext( contextEntityType ); if ( contextEntity != null && contextEntity is DotLiquid.ILiquidizable ) { var type = Type.GetType( contextEntityType.AssemblyName ?? contextEntityType.Name ); if ( type != null ) { contextObjects.Add( type.Name, contextEntity ); } } } if ( contextObjects.Any() ) { mergeFields.Add( "Context", contextObjects ); } mergeFields.Add( "RockVersion", Rock.VersionInfo.VersionInfo.GetRockProductVersionNumber() ); html = content.Content.ResolveMergeFields( mergeFields ); // show merge fields if enable debug true if ( enableDebug && IsUserAuthorized( Authorization.EDIT ) ) { // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line mergeFields.Remove( "Person" ); html += mergeFields.lavaDebugInfo(); } } else { html = content.Content; } } else { html = string.Empty; } } // Resolve any dynamic url references string appRoot = ResolveRockUrl( "~/" ); string themeRoot = ResolveRockUrl( "~~/" ); html = html.Replace( "~~/", themeRoot ).Replace( "~/", appRoot ); // cache content int cacheDuration = GetAttributeValue( "CacheDuration" ).AsInteger(); if ( cacheDuration > 0 ) { HtmlContentService.AddCachedContent( this.BlockId, entityValue, html, cacheDuration ); } } else { html = cachedContent; } // add content to the content window lHtmlContent.Text = html; }
/// <summary> /// Shows the view. /// </summary> protected void ShowView() { mdEdit.Hide(); pnlEditModel.Visible = false; upnlHtmlContent.Update(); // prevent htmlEditor from using viewstate when not needed pnlEdit.EnableViewState = false; pnlEdit.Visible = false; pnlVersionGrid.Visible = false; string entityValue = EntityValue(); string html = string.Empty; string cachedContent = HtmlContentService.GetCachedContent( this.BlockId, entityValue ); // if content not cached load it from DB if ( cachedContent == null ) { using ( var rockContext = new RockContext() ) { var htmlContentService = new HtmlContentService( rockContext ); HtmlContent content = htmlContentService.GetActiveContent( this.BlockId, entityValue ); if ( content != null ) { bool enableDebug = GetAttributeValue( "EnableDebug" ).AsBoolean(); if ( content.Content.HasMergeFields() || enableDebug ) { var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( this.RockPage, this.CurrentPerson ); mergeFields.Add( "CurrentPage", Rock.Lava.LavaHelper.GetPagePropertiesMergeObject( this.RockPage ) ); if ( CurrentPerson != null ) { // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line mergeFields.AddOrIgnore( "Person", CurrentPerson ); } mergeFields.Add( "RockVersion", Rock.VersionInfo.VersionInfo.GetRockProductVersionNumber() ); mergeFields.Add( "CurrentPersonCanEdit", IsUserAuthorized( Authorization.EDIT ) ); mergeFields.Add( "CurrentPersonCanAdministrate", IsUserAuthorized( Authorization.ADMINISTRATE ) ); html = content.Content.ResolveMergeFields( mergeFields ); // show merge fields if enable debug true if ( enableDebug && IsUserAuthorized( Authorization.EDIT ) ) { // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line mergeFields.Remove( "Person" ); html += mergeFields.lavaDebugInfo(); } } else { html = content.Content; } } else { html = string.Empty; } } // Resolve any dynamic url references string appRoot = ResolveRockUrl( "~/" ); string themeRoot = ResolveRockUrl( "~~/" ); html = html.Replace( "~~/", themeRoot ).Replace( "~/", appRoot ); // cache content int cacheDuration = GetAttributeValue( "CacheDuration" ).AsInteger(); if ( cacheDuration > 0 ) { HtmlContentService.AddCachedContent( this.BlockId, entityValue, html, cacheDuration ); } } else { html = cachedContent; } // add content to the content window lHtmlContent.Text = html; }