private Template GetTemplate() { var cacheTemplate = LavaTemplateCache.Get(TemplateCacheKey, GetAttributeValue("Template")); return(cacheTemplate != null ? cacheTemplate.Template : null); }
/// <summary> /// Handles the OnSave event of the masterPage control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void masterPage_OnSave(object sender, EventArgs e) { bool reloadPage = false; int blockId = Convert.ToInt32(PageParameter("BlockId")); if (Page.IsValid) { var rockContext = new RockContext(); var blockService = new Rock.Model.BlockService(rockContext); var block = blockService.Get(blockId); block.LoadAttributes(); block.Name = tbBlockName.Text; block.CssClass = tbCssClass.Text; block.PreHtml = cePreHtml.Text; block.PostHtml = cePostHtml.Text; block.OutputCacheDuration = 0; //Int32.Parse( tbCacheDuration.Text ); rockContext.SaveChanges(); avcAttributes.GetEditValues(block); avcAdvancedAttributes.GetEditValues(block); SaveCustomColumnsConfigToViewState(); if (this.CustomGridColumnsConfigState != null && this.CustomGridColumnsConfigState.ColumnsConfig.Any()) { if (!block.Attributes.Any(a => a.Key == CustomGridColumnsConfig.AttributeKey)) { block.Attributes.Add(CustomGridColumnsConfig.AttributeKey, null); } var customGridColumnsJSON = this.CustomGridColumnsConfigState.ToJson(); if (block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey) != customGridColumnsJSON) { block.SetAttributeValue(CustomGridColumnsConfig.AttributeKey, customGridColumnsJSON); // if the CustomColumns changed, reload the whole page so that we can avoid issues with columns changing between postbacks reloadPage = true; } } else { if (block.Attributes.Any(a => a.Key == CustomGridColumnsConfig.AttributeKey)) { if (block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey) != null) { // if the CustomColumns were removed, reload the whole page so that we can avoid issues with columns changing between postbacks reloadPage = true; } block.SetAttributeValue(CustomGridColumnsConfig.AttributeKey, null); } } if (tglEnableStickyHeader.Checked) { if (!block.Attributes.Any(a => a.Key == CustomGridOptionsConfig.EnableStickyHeadersAttributeKey)) { block.Attributes.Add(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey, null); } } if (block.GetAttributeValue(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey).AsBoolean() != tglEnableStickyHeader.Checked) { block.SetAttributeValue(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey, tglEnableStickyHeader.Checked.ToTrueFalse()); // if EnableStickyHeaders changed, reload the page reloadPage = true; } block.SaveAttributeValues(rockContext); // If this is a page menu block then we need to also flush the LavaTemplateCache for the block ID if (block.BlockType.Guid == Rock.SystemGuid.BlockType.PAGE_MENU.AsGuid()) { var cacheKey = string.Format("Rock:PageMenu:{0}", block.Id); LavaTemplateCache.Remove(cacheKey); } StringBuilder scriptBuilder = new StringBuilder(); if (reloadPage) { scriptBuilder.AppendLine("window.parent.location.reload();"); } else { scriptBuilder.AppendLine(string.Format("window.parent.Rock.controls.modal.close('BLOCK_UPDATED:{0}');", blockId)); } ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "close-modal", scriptBuilder.ToString(), true); } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { LavaShortcode lavaShortcode; var rockContext = new RockContext(); var lavaShortCodeService = new LavaShortcodeService(rockContext); int lavaShortCode = hfLavaShortcodeId.ValueAsInt(); if (lavaShortCodeService.Queryable().Any(a => a.TagName == tbTagName.Text && a.Id != lavaShortCode)) { Page.ModelState.AddModelError("DuplicateTag", "Tag with the same name is already in use."); return; } if (lavaShortCode == 0) { lavaShortcode = new LavaShortcode(); lavaShortCodeService.Add(lavaShortcode); } else { lavaShortcode = lavaShortCodeService.Get(lavaShortCode); } var oldTagName = hfOriginalTagName.Value; lavaShortcode.Name = tbLavaShortcodeName.Text; lavaShortcode.IsActive = cbIsActive.Checked; lavaShortcode.Description = tbDescription.Text; lavaShortcode.Documentation = htmlDocumentation.Text; lavaShortcode.TagType = rblTagType.SelectedValueAsEnum <TagType>(); lavaShortcode.TagName = tbTagName.Text.Trim(); lavaShortcode.Markup = ceMarkup.Text; lavaShortcode.Parameters = kvlParameters.Value; lavaShortcode.EnabledLavaCommands = String.Join(",", lcpLavaCommands.SelectedLavaCommands); rockContext.SaveChanges(); if (LavaService.RockLiquidIsEnabled) { // unregister shortcode if (oldTagName.IsNotNullOrWhiteSpace()) { Template.UnregisterShortcode(oldTagName); } // Register the new shortcode definition. Note that RockLiquid shortcode tags are case-sensitive. if (lavaShortcode.TagType == TagType.Block) { Template.RegisterShortcode <Rock.Lava.Shortcodes.DynamicShortcodeBlock>(lavaShortcode.TagName); } else { Template.RegisterShortcode <Rock.Lava.Shortcodes.DynamicShortcodeInline>(lavaShortcode.TagName); } // (bug fix) Now we have to clear the entire LavaTemplateCache because it's possible that some other // usage of this shortcode is cached with a key we can't predict. #pragma warning disable CS0618 // Type or member is obsolete // This obsolete code can be deleted when support for the DotLiquid Lava implementation is removed. LavaTemplateCache.Clear(); #pragma warning restore CS0618 // Type or member is obsolete } if (oldTagName.IsNotNullOrWhiteSpace()) { LavaService.DeregisterShortcode(oldTagName); } // Register the new shortcode definition. LavaService.RegisterShortcode(lavaShortcode.TagName, (shortcodeName) => WebsiteLavaShortcodeProvider.GetShortcodeDefinition(shortcodeName)); LavaService.ClearTemplateCache(); NavigateToParentPage(); }
/// <summary> /// Handles the BlockUpdated event of the PageMenu control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void PageMenu_BlockUpdated(object sender, EventArgs e) { LavaTemplateCache.Remove(CacheKey()); }