Giter Club home page Giter Club logo

mjml-aspnetcore's Introduction

mjml-aspnetcore

Nuget NuGet version

MJML is a responsive email templating system. You can find more information on MJML here: https://mjml.io/. Current Version: 4.6.3

As of v1.3.0, Mjml-AspNetCore uses Jering.Javascript.NodeJS (https://github.com/JeringTech/Javascript.NodeJS) to invoke NodeJS.

A render script has been bundled and will call the MJML renderer and return the compiled script.

var prehtml = "<mjml><mj-body></mj-body></mjml>";
var result = await _mjmlServices.Render(prehtml);

You can also use JSON instead of XML, as described here: https://mjml.io/documentation/#using-mjml-in-json

var view = 
@"{
    tagName: 'mjml',
    attributes: {},
    children: [{
        tagName: 'mj-body',
        attributes: {},
        children: [{
            tagName: 'mj-section',
            attributes: {},
            children: [{
                tagName: 'mj-column',
                attributes: {},
                children: [{
                    tagName: 'mj-image',
                    attributes: {
                        'width': '100px',
                        'src': '/assets/img/logo-small.png'
                    }
                },
                {
                    tagName: 'mj-divider',
                    attributes: {
                        'border-color' : '#F46E43'
                    }
                }, 
                {
                    tagName: 'mj-text',
                    attributes: {
                        'font-size': '20px',
                        'color': '#F45E43',
                        'font-family': 'Helvetica'
                    },
                    content: 'Hello World'
                }]
            }]
        }]
    }]
}";
var result = await mjml.RenderFromJson(view);

You can add dependancy support in your startup.cs file like this:

// add render services
services.AddMjmlServices(o =>
{
    if (Environment.IsDevelopment())
    {
        o.DefaultKeepComments = true;
        o.DefaultBeautify = true;
    }
    else
    {
        o.DefaultKeepComments = false;
        o.DefaultMinify = true;
    }
});

mjml-aspnetcore's People

Contributors

dependabot[bot] avatar jaben avatar jpknoll avatar sebastianstehle avatar srkirkland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mjml-aspnetcore's Issues

AddNodeServices options

Hi!

Great library. It works perfectly for us.

We had a little logging issue on our end:

When an mjml parsing error happened because of incorrect mjml, it was not put inside the MjmlResponseErrors of the result.

So we had to put a try catch around it:

            var result = new MjmlResponse();
            try
            {
                result = await _mjmlService.Render(rendered);
            }
            catch (Exception e)
            {

            }

But even when we were not throwing any errors nor using doing ILogger.LogError(...) anywhere, it was still logging errors because of the options of AddNodeServices(...).

Maybe it could be a good idea to add the node services options as a argument in AddMjmlServices.

This could be the signature:

public static void AddMjmlServices(this IServiceCollection serviceCollection, Action<MjmlServiceOptions> configure, Action<NodeServicesOptions> configureNode);

In the meantime, to deactivate error logs, we do the following:

            services.AddNodeServices(o =>
            {
                o.NodeInstanceOutputLogger = new NoLog();
            });
            var mjmlServiceOptions = new MjmlServiceOptions();
            if (Environment.IsDevelopment())
            {
                mjmlServiceOptions.DefaultKeepComments = true;
                mjmlServiceOptions.DefaultBeautify = true;
            }
            else
            {
                mjmlServiceOptions.DefaultKeepComments = true;
                mjmlServiceOptions.DefaultMinify = true;
            }

            services.AddSingleton(mjmlServiceOptions);
            services.AddSingleton<IMjmlServices, MjmlServices>();

Thanks!

Version?

Can you specify or show the version that the mjml is using?

Add support for other mjml options

Hi,

I am testing your library and it works well, thanks !
I wanted to experiment inclusion of sub-templates and store them in a separated folder but there seems to be missing options to specify argument 'filePath' of the mjml2html function.
It would be great if you could implement other mjml2html options so that we could leverage sub-templates.
Thanks you for your support :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.