MI Guide
  • Gitlab
  • Server Requirement
  • Laragon 6
  • Style Guide
    • Html Style Guide
    • CSS Style Guide
      • Sass Rules
      • Typograph Styling
    • JS Style Guide
    • Elementor Style Guide
      • Rules
      • Algemene and Privacy Template
      • Custom Elementor Widget
    • Responsive and space Guide
  • Setup Project
    • Add a reCAPTCHA to a WordPress website (for dummies)
    • Elementor
    • Tutorial how to change theme name
    • Setup SMTP
  • Project Deployment v1.2.1
    • Deployment Checklist
    • #Project Repository v22.0
    • #Local Environment v22.0
    • #Staging Environment v22.0
    • #Deployment via Git
  • Cache
    • Nitropack - Delete footer banner
    • Wordpress Cache
  • SEO
  • Plugins
    • Sendcloud
    • WooCommerce
      • WooCommerce Loop
      • Vat/Tax deduction for valid tax number
      • Setup Mollie
      • Add Wishlist counter [yith] JS
  • Reference articles, links or others that help in developing
  • Elementor
    • Tutorial to make custom elementor widget in our theme
    • How to add custom font
    • Algemen common case
    • How to regenerate css
  • Divi
    • Add Slick slider to Divi
    • How to use dynamic condition on DIVI
    • How to embed Google Maps on Divi
    • References to help in the development (DIVI)
    • How to enable classic editor on divi
    • How to add custom font
    • Custom divi menu/hamburger breakpoint
    • Divi custom container width
    • Allow SVG upload without plugin
    • Divi font weight cannot set to 400
    • How to regenerate css
  • Optimize Image
  • Common Issue
    • Woocommerce thumbnail blurry
    • FAQ link Height
    • Jquery
    • Custom Checkbox
    • Svg Tips
    • Webp Converter Plugin - Server Konfiguration Error
  • Plugin list
  • Frontend things
    • Frontend Guide
    • MJML
  • Backend things
    • 👺Custom Template Mail
    • 🦄Fun Function
    • 🦽OOP
    • 🗑️Woocommerce
    • 🚨Woocommerce Templating Override
    • 🚀Gravity Form Hook
    • ⛈️FREQUENT ISSUES
    • 😱HOOK
    • 🐆Page Speed for Backend
    • 🤝Sharing Databases
    • 🙉JS for Backend Purposes
      • 💸Penamaan folder, penulisan kode dan pengetahuan dasar
      • 🏃‍♂️Ajax request on wordpress
      • 🥷Woocommerce JS Event
    • 🦸‍♂️HELPERS
Powered by GitBook
On this page
  1. Backend things

Custom Template Mail

Only Read this doc can't make you as a master

PreviousBackend thingsNextFun Function

Last updated 1 year ago

Step 1: Set Up MJML in your WordPress Theme

  • Access your WordPress theme files either via FTP or the theme editor in the WordPress dashboard.

  • Create a new folder called "mjml" inside your theme directory.

  • Download the MJML framework from the official website () and extract its contents.

  • Copy the "mjml.min.js" and "mjml.js" files from the extracted folder into the "mjml" folder you created in your theme directory.

Step 2: Create a Custom Template Mail File

  • Create a new PHP file in your theme directory and name it something like "custom-template-mail.php".

  • Open the file and add the following code at the beginning:

<?php
/*
Template Name: Custom Template Mail
*/

Step 3: Design Your Template Using MJML Syntax

  • Within the "custom-template-mail.php" file, write your template using MJML syntax.

  • You can use HTML and MJML tags to structure your email template.

  • Remember to include the necessary MJML scripts to convert MJML code to HTML.

<?php
/*
Template Name: Custom Template Mail
*/

get_header(); ?>

<!-- Your MJML code goes here -->

<?php get_footer(); ?>

Step 4: Convert MJML to HTML

  • To convert MJML code to HTML, you need to use the MJML engine.

  • Add the following code to your "custom-template-mail.php" file after your MJML code:

<script src="<?php echo get_template_directory_uri(); ?>/mjml/mjml.min.js"></script>
<script>
  // Get the MJML code from the DOM
  var mjmlCode = document.querySelector('#your-mjml-container').innerHTML;

  // Convert MJML to HTML
  var htmlOutput = mjml.mjml2html(mjmlCode);

  // Inject the HTML into the DOM
  document.querySelector('#your-html-container').innerHTML = htmlOutput.html;
</script>

Step 5: Create a WordPress Page

  • In the WordPress dashboard, create a new page and assign the "Custom Template Mail" template to it.

  • Save the page and view it to see your custom template mail rendered in HTML.

Note: Remember to replace "your-mjml-container" and "your-html-container" with the appropriate IDs or classes of your MJML and HTML containers.

👺
https://mjml.io/