Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question - How to use premailer.net with RazorEngine #2

Open
Martin-Andersen opened this issue Nov 9, 2017 · 1 comment
Open

Question - How to use premailer.net with RazorEngine #2

Martin-Andersen opened this issue Nov 9, 2017 · 1 comment

Comments

@Martin-Andersen
Copy link

You are singing the praise of Premailer.Net but not using it.
Where in the rendering flow should I use PreMailer?

@Martin-Andersen
Copy link
Author

I can see that RazorEngine are a moving target. Don't know if you have been working with version 3.1
I have started to write some code but I am not sure on how to cache the template.

private static void ConfigureRazorEngineEmailSettings(IAppBuilder app, Container container, AppSettingsRepository settings)
{
    var templateFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EmailTemplates");
    var config = new TemplateServiceConfiguration();
    config.Namespaces.Add("Goo.Web.Api.Models");
    var service = RazorEngineService.Create(config);

    var html = File.ReadAllText(Path.Combine(templateFolderPath, "SuggestNewWord.cshtml"));
    var htmlSuggestNewWord = PreMailer.Net.PreMailer.MoveCssInline(html);

    // do we need this
    service.AddTemplate("SuggestNewWord", htmlSuggestNewWord.Html);
    var emailBody = service.RunCompile("SuggestNewWord", typeof(AboutPosFormModel));

    // run this code in a API controller
    emailBody = service.Run("SuggestNewWord", typeof(AboutPosFormModel), new AboutPosFormModel());
}

There are RunCompile and Run. I guess that I use RunCompile in the setup and Run in my controllers.
Then there are service.AddTemplate this is a little confusing because RunCompile with a key should cache the template.

Thanks for the articles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant