/// <summary> /// Initializes this instance. /// </summary> public bool TryRunFrontMatter(IFrontMatter frontMatter, TemplateObject obj, ScriptObject newGlobal = null) { if (frontMatter == null) { throw new ArgumentNullException(nameof(frontMatter)); } if (obj == null) { throw new ArgumentNullException(nameof(obj)); } var context = CreatePageContext(); context.PushGlobal(obj); if (newGlobal != null) { context.PushGlobal(newGlobal); } try { context.EnableOutput = false; context.TemplateLoader = new TemplateLoaderFromIncludes(Site); Site.SetValue(PageVariables.Site, this, true); frontMatter.Evaluate(context); } catch (ScriptRuntimeException exception) { LogException(exception); return(false); } return(true); }
/// <summary> /// Initializes this instance. /// </summary> public bool TryRunFrontMatter(IFrontMatter frontMatter, ContentObject obj) { if (frontMatter == null) { throw new ArgumentNullException(nameof(frontMatter)); } if (obj == null) { throw new ArgumentNullException(nameof(obj)); } var context = new TemplateContext(Builtins); context.PushGlobal(obj); try { context.EnableOutput = false; context.TemplateLoader = new TemplateLoaderFromIncludes(Site); Site.SetValue(PageVariables.Site, this, true); frontMatter.Evaluate(context); } catch (ScriptRuntimeException exception) { LogException(exception); return(false); } finally { context.PopGlobal(); // We don't keep the site variable after this initialization Site.Remove(PageVariables.Site); } return(true); }