Skip to content

Examples of Generating from templates

michael-freidgeim-webjet edited this page Jul 7, 2019 · 1 revision

The examples extend the Quickstart examples from Readme.md.

Embedded Resource

If I have a template MyTemplate.cshtml embedded resource in folder TemplatesFolder and MyModel myModel

var body = await GenerateEmailBodyAsync(myModel, "TemplatesFolder." + templateFileName);

where

    private async Task<string> GenerateEmailBodyAsync(MyModel myModel , string templatePath )
    {
        var engine = new RazorLightEngineBuilder()
            .UseEmbeddedResourcesProject(typeof(Program))
            .UseMemoryCachingProvider() 
            .Build();
         string result = await engine.CompileRenderAsync(templatePath , myModel ,  null);
        return result;
    }