public async Task <string> Generate(Guid templateId, object data) { var template = await _templateRepository.GetByIdAsync(templateId); var generate = _templateEngine.Compile(template.Value ?? ""); return(generate(data)); }
public ITemplate GetOrAdd(string name, Func <string> sourceFactory) { Guard.NotEmpty(name, nameof(name)); Guard.NotNull(sourceFactory, nameof(sourceFactory)); return(_templates.GetOrAdd(name, key => { return _engine.Compile(sourceFactory()); })); }
public string Get() { // var engine = HttpContext.RequestServices.GetService(typeof(ITemplateEngine<Engines.DotLiquid.ViewModelOptions>)); var template = dotLiquidTemplateEngine.Compile(RawTemplate); Hash hash = new Hash(); hash["name"] = "DotLiquid"; return(template.Render(new Engines.DotLiquid.ViewModelOptions { Hash = hash })); }
public string Get(int id) { var template = handlebarsTemplateEngine.Compile(RawTemplate); var obj = new { name = "Handlebars" }; return(template.Render(new Engines.Handlebars.ViewModelOptions { Object = obj })); }
private string RenderBodyTemplate(MessageContext ctx) { var key = BuildTemplateKey(ctx); var source = ctx.MessageTemplate.GetLocalized((x) => x.Body, ctx.Language); var fromCache = true; var template = _templateManager.GetOrAdd(key, GetBodyTemplate); if (fromCache && template.Source != source) { // The template was resolved from template cache, but it has expired // because the source text has changed. template = _templateEngine.Compile(source); _templateManager.Put(key, template); } return(template.Render(ctx.Model, ctx.FormatProvider)); string GetBodyTemplate() { fromCache = false; return(source); } }
public ITemplate GetOrAdd(string name, Func <string> sourceFactory) { return(_templates.GetOrAdd(name, key => _engine.Compile(sourceFactory()))); }
private string Render(string template, IFormatProvider formatProvider, object data) { var tpl = _engine.Compile(template); return(tpl.Render(data, formatProvider)); }