1/2/2024 0 Comments Mjml formsHere, we’ll use mjml-core, in charge of rendering MJML and the section, column, image and text components. This includes React but also MJML components that we’ll reuse. Importing dependenciesįirst, we need to import dependencies. All the code snippets below are taken from the file MjColumnImageText.js located in the components folder. Let’s split the code of our custom component bits by bits. The great thing with MJML components is that you can create them using HTML but also MJML. Feel free to add more attributes to Section, Column, Image or Text following the same structure (given the components support the attributes you use).The style of the text thanks to the attributes color, font-size.The style of the image thanks to the attributes image-padding, image-src, image-width.The direction of the component (whether the image should be on the left or right) thanks to the attribute direction.Here is what we will be able to customise thanks to the components attributes: Now, we obviously want to make some of the content of this component dynamic so we can customise it when using the component. It is intentionally basic as the idea is to show you how to create your own component specific to your need. We’ll create a simple component that display a 2 column layout with an image on the left part and a text on the right part. If you don’t want to automatically watch and recompile the files, you can simply run npm run build to compile them manually whenever you want. Run npm start so that index.mjml and your custom components are recompiled at each edit you’ll make. To get the local path from your terminal, run pwd ( echo %cd% on Windows). mjmlconfig in your terminal and replace the path to /lib/MjColumnImageText.js to your local path to this file. The file will probably be hidden by default when you browse the folder. mjmlconfig file where you are registering your custom components so they can be used by the MJML engine which wouldn’t know them otherwise.įirst, it is important that you change the path to your component in. You should not edit the files in this folder. A lib folder, where custom components compiled from ES6 to ES5 with babel are located.A components folder, where your custom components written in ES6 are located.From the application code's point of view, it's just rendering FreeMarker template files using the normal FreeMarker API. I use the gradle-node-plugin to run the MJML renderer in the build. This is where your MJML lives and where we will use the custom component (uncomment it to use it!). ftlh files (the file extension that tells FreeMarker it's dealing with HTML). The most important elements of this boilerplate are: While you’re installing dependencies, let’s go over what is in this folder. Then, run npm install to install the dependencies. To do so, just open your terminal (go to wherever you want your folder to be created) and run git clone & cd mjml-component-boilerplate. Don’t worry though, we got you covered with a boilerplate so all you have to do is clone the component boilerplate. Since MJML is written in ES6, it is dependant on a few things like Babel. MJML comes with several installing options for different platforms: MJML App - This app is built just for MJML, it has an editor and live preview feature. I have designed a minimal email template: How to install MJML. Let’s walk you through the component creation process. We will code an email template design using MJML in this blog post. Added to the standard library of components, it is possible for anyone to create their own component, leveraging MJML’s easy syntax to make it easier to reuse bits of code without having to type them over and over. MJML is built upon components, used under the form of tags in the markup language. Tutorial: creating your own MJML component
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |