or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-6/

Email Template Generator with JSON Input

Build a programmatic email template generator that creates MJML templates using JSON objects instead of XML strings. The generator should construct a complete responsive email template with a header, content sections, and footer.

Requirements

Create a function generateEmailTemplate(data) that:

  1. Accepts a data object containing email content (subject, heading, message, button text/URL, footer text)
  2. Constructs an MJML template using JSON object format (not XML strings)
  3. Compiles the JSON MJML to HTML and returns the result
  4. Returns an object with html and any errors from compilation

The email should have this structure:

  • A header section with a colored background containing the heading
  • A main content section with the message text
  • A call-to-action button
  • A footer section with smaller text

Implementation

@generates

API

/**
 * Generates an email template from data using MJML JSON format
 * @param {Object} data - Email content data
 * @param {string} data.heading - Main heading text
 * @param {string} data.message - Body message text
 * @param {string} data.buttonText - CTA button text
 * @param {string} data.buttonUrl - CTA button URL
 * @param {string} data.footerText - Footer text
 * @returns {Object} Result object with html and errors properties
 */
function generateEmailTemplate(data) {
  // Implementation here
}

module.exports = { generateEmailTemplate };

Test Cases

  • It generates HTML output when given valid data @test
  • It includes the heading text in the output HTML @test
  • It includes the button with correct URL in the output HTML @test
  • It returns errors array when JSON structure is invalid @test

Dependencies { .dependencies }

mjml { .dependency }

Provides MJML to HTML compilation with JSON input support.