/// <summary> /// Adds variable parameters to the virtual path to allow caching of multiple versions based on parameters. /// </summary> /// <param name="layoutVirtualPath">The layout virtual path.</param> /// <returns>The path with appended variables.</returns> protected virtual string AddVariablesToPath(string layoutVirtualPath) { var varies = new List <string>(); var packagesManager = new PackageManager(); var currentPackage = packagesManager.GetCurrentPackage(); if (!currentPackage.IsNullOrEmpty()) { varies.Add(currentPackage); } if (SystemManager.CurrentContext.AppSettings.Multilingual) { varies.Add(CultureInfo.CurrentUICulture.Name); } if (MasterPageBuilder.IsFormTagRequired()) { varies.Add("form"); } else { varies.Add("noform"); } var pageData = MasterPageBuilder.GetRequestedPageData(); if (pageData != null) { varies.Add(pageData.Id.ToString()); varies.Add(pageData.Version.ToString(CultureInfo.InvariantCulture)); } layoutVirtualPath = (new VirtualPathBuilder()).AddParams(layoutVirtualPath, string.Join("_", varies)); return(layoutVirtualPath); }
/// <summary> /// Processes the layout string adding the required attributes to the head tag /// and also adding the required form tag. /// </summary> /// <param name="targetTemplate">The template.</param> /// <returns></returns> public virtual string ProcessLayoutString(string targetTemplate) { var includeFormTag = MasterPageBuilder.IsFormTagRequired(); StringBuilder outPut = new StringBuilder(); HtmlChunk chunk = null; using (HtmlParser parser = new HtmlParser(targetTemplate)) { parser.SetChunkHashMode(false); parser.AutoExtractBetweenTagsOnly = false; parser.CompressWhiteSpaceBeforeTag = false; parser.KeepRawHTML = true; bool setTitle = true; bool modified; bool isOpenBodyTag; bool isCloseBodyTag; bool isClosedHeadTag; while ((chunk = parser.ParseNext()) != null) { modified = false; isOpenBodyTag = false; isCloseBodyTag = false; isClosedHeadTag = false; if (chunk.Type == HtmlChunkType.OpenTag) { if (chunk.TagName.Equals("head", StringComparison.OrdinalIgnoreCase)) { if (!chunk.HasAttribute("runat")) { chunk.SetAttribute("runat", "server"); modified = true; } } else if (chunk.TagName.Equals("body", StringComparison.OrdinalIgnoreCase)) { isOpenBodyTag = true; } else if (chunk.TagName.Equals("title", StringComparison.OrdinalIgnoreCase)) { setTitle = false; } } else if (chunk.Type == HtmlChunkType.CloseTag) { if (chunk.TagName.Equals("body", StringComparison.OrdinalIgnoreCase)) { isCloseBodyTag = true; } if (chunk.TagName.Equals("head", StringComparison.OrdinalIgnoreCase)) { isClosedHeadTag = true; } } if (includeFormTag && isCloseBodyTag) { outPut.Append("</form>"); } else if (!includeFormTag && isClosedHeadTag) { this.AppendRequiredHeaderContent(outPut, setTitle); } if (modified) { outPut.Append(chunk.GenerateHtml()); } else { outPut.Append(chunk.Html); } if (includeFormTag && isOpenBodyTag) { outPut.Append("<form runat='server'>"); } } } return(outPut.ToString()); }