https://github.com/techwritescode/meteor-mjml
A MJML rendering helper for Meteor.js
https://github.com/techwritescode/meteor-mjml
Last synced: 12 months ago
JSON representation
A MJML rendering helper for Meteor.js
- Host: GitHub
- URL: https://github.com/techwritescode/meteor-mjml
- Owner: techwritescode
- Created: 2016-08-10T20:13:23.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-09-26T23:29:11.000Z (over 7 years ago)
- Last Synced: 2025-06-29T19:30:42.501Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 11
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MJML For Meteor
MJML is a markup language designed to reduce the pain of coding a responsive email. [Visit MJML more information ](https://mjml.io)
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](https://docs.meteor.com/api/email.html)
### Examples:
Make sure you have the `MAIL_URL` environment variable set in Meteor, see [here](https://docs.meteor.com/api/email.html).
#### Basic MJML Email With Templating:
#### `server.js`
```javascript
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`
```xml
{{message}}
```
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`
```javascript
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`
```xml
{{> header }}
this is the other content
```
#### `header.mjml`
```xml
```
This will send an email with a image in the header.