/// <summary> /// Handles the Click event of the lbGenerate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void lbGenerate_Click(object sender, EventArgs e) { var blockTypes = GetQuery().ToList(); var ids = gBlockTypes.SelectedKeys.Cast <int>().ToList(); if (ids.Any()) { blockTypes = blockTypes.Where(b => ids.Contains(b.Id)).ToList(); } blockTypes.ForEach(b => b.LoadAttributes()); string lavaTemplate = GetAttributeValue("LavaTemplate"); var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(RockPage); mergeFields.Add("BlockTypes", blockTypes); DotLiquid.Template template = DotLiquid.Template.Parse(lavaTemplate); DotLiquid.RenderParameters parameters = new DotLiquid.RenderParameters { LocalVariables = DotLiquid.Hash.FromDictionary(mergeFields), Filters = new Type[] { typeof(LavaAdditions) } }; lResults.Text = template.Render(parameters).EncodeHtml(); pResults.Visible = true; }
public void RenderTemplate(string templateFilePath, TextWriter htmlTextWriter, dynamic model) { var template = DotLiquid.Template.Parse(File.ReadAllText(templateFilePath)); var templateRenderParameters = new DotLiquid.RenderParameters(); var directorySeparator = Path.DirectorySeparatorChar.ToString(); var templateDirectory = Path.GetFullPath( (templateFilePath.StartsWith(directorySeparator, StringComparison.InvariantCultureIgnoreCase) || templateFilePath.StartsWith("." + directorySeparator, StringComparison.InvariantCultureIgnoreCase)) ? Path.GetDirectoryName(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, templateFilePath)) : Path.GetDirectoryName(templateFilePath) ); DotLiquid.Template.FileSystem = new DotLiquid.FileSystems.LocalFileSystem(templateDirectory); templateRenderParameters.LocalVariables = model is System.Dynamic.ExpandoObject ? DotLiquid.Hash.FromDictionary(model as IDictionary<string, object>) : DotLiquid.Hash.FromAnonymousObject(model) ; template.Render(htmlTextWriter, templateRenderParameters); htmlTextWriter.Flush(); }
public void RenderTemplate(string templateFilePath, TextWriter htmlTextWriter, dynamic model) { var template = DotLiquid.Template.Parse(File.ReadAllText(templateFilePath)); var templateRenderParameters = new DotLiquid.RenderParameters(); var directorySeparator = Path.DirectorySeparatorChar.ToString(); var templateDirectory = Path.GetFullPath( (templateFilePath.StartsWith(directorySeparator, StringComparison.InvariantCultureIgnoreCase) || templateFilePath.StartsWith("." + directorySeparator, StringComparison.InvariantCultureIgnoreCase)) ? Path.GetDirectoryName(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, templateFilePath)) : Path.GetDirectoryName(templateFilePath) ); DotLiquid.Template.FileSystem = new DotLiquid.FileSystems.LocalFileSystem(templateDirectory); templateRenderParameters.LocalVariables = model is System.Dynamic.ExpandoObject ? DotLiquid.Hash.FromDictionary(model as IDictionary <string, object>) : DotLiquid.Hash.FromAnonymousObject(model) ; template.Render(htmlTextWriter, templateRenderParameters); htmlTextWriter.Flush(); }