/// <summary>合并</summary> /// <param name="context">上下文环境</param> /// <param name="templatePath">模板相对路径</param> /// <returns></returns> public string Merge(VelocityContext context, string templatePath) { try { if (engine.TemplateExists(templatePath)) { Template template = engine.GetTemplate(templatePath); return(Merge(context, template)); } else { return("Can't find \"" + templatePath + "\"."); } } catch { // 发生内部错误, 重启引擎. instance = null; engine = null; return(string.Empty); } }
/// <summary>求值</summary> /// <param name="context">上下文环境</param> /// <param name="templateValue">模板信息</param> /// <returns></returns> public string Evaluate(VelocityContext context, string templateValue) { try { StringWriter writer = new StringWriter(); engine.Evaluate(context, writer, string.Empty, templateValue); return(writer.GetStringBuilder().ToString()); } catch { // 发生内部错误, 重启引擎. instance = null; engine = null; throw; } }