예제 #1
0
 /// <inheritdoc />
 public virtual void Render(TextWriter writer, TemplateContext context)
 {
     if (templateResult == null)
     {
         if (this.Context.Mode == EngineMode.Interpreted)
         {
             templateResult = context.InterpretTemplate(this.TemplateKey, this.reader);
         }
         else
         {
             templateResult = context.CompileTemplate(this.TemplateKey, this.reader);
         }
         if (templateResult == null)
         {
             throw new TemplateException($"template error.");
         }
     }
     try
     {
         templateResult.Render(writer, context);
     }
     catch (System.Exception e)
     {
         context.AddError(e);
     }
 }
예제 #2
0
        private string InterpretParse(string name, TemplateContext ctx, IReader reader)
        {
            var result = ctx.InterpretTemplate(name, reader);

            using (var write = new System.IO.StringWriter())
            {
                result.Render(write, ctx);
                return(write.ToString());
            }
        }