Coder Social home page Coder Social logo

meteor-mjml's Introduction

MJML For Meteor

MJML is a markup language designed to reduce the pain of coding a responsive email. Visit MJML more information

MJML For Meteor allows you to use MJML inside Meteor and includes enhanced functionality like Handlebars for conditional statements and file includes.

To include for an example a header.mjml file in your email template use: {{> header }} and it will load that MJML file as long as the file is in the same directory.

Includes all Handlebars functionality.

API

new MJML(filepath)

Returns a new MJML Email instance

.helpers(helpers)

Pass all your Handlebars helpers into this function

.compile()

Returns a compiled version of your email

.send()

Calls Meteor's Email.send function, more documentation here

Examples:

Make sure you have the MAIL_URL environment variable set in Meteor, see here.

Basic MJML Email With Templating:

server.js

var email = new MJML('../path-to-your/file.mjml');
email.helpers({
  message:"Hello World"
});

email.send({
  to: "to@email",
  from: "from@email",
  subject: "Just Testing..."
});

file.mjml

<mjml>
    <mj-body>
	    <mj-container>
	        <mj-text>{{message}}</mj-text>
        </mj-container>
    </mj-body>
</mjml>

This will Compile And Send A MJML Email.

MJML file with reuseable includes:

Example directory structure could look like this:

├── mjml
│   ├── header.mjml
│   └── body.mjml
│    server.js

server.js

	var email = new MJML('./mjml/body.mjml');
    email.helpers({
        message: "hello world"
    });
    email.send({
        to: "to@email",
        from: "from@email",
        subject: "Hello World"
    });

body.mjml

	<mjml>
		<mj-body>
			<mj-container>
				{{> header }}
				<mj-section>
					<mj-text>this is the other content</mj-text>
				</mj-section>
			</mj-container>
		</mj-body>
	</mjml>

header.mjml

<mj-section>
	<mj-image width="300" src="http://www.online-image-editor.com//styles/2014/images/example_image.png">
</mj-section>

This will send an email with a image in the header.

meteor-mjml's People

Contributors

mkorban avatar yuvalyn avatar

Watchers

James Cloos avatar

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.