Git Product home page Git Product logo

mjml-nette's Introduction

MJML integration into Nette Framework.

Build Status Licence Latest stable PHPStan

Installation

The recommended way to is via Composer:

composer require surda/mjml-nette

After that you have to register extensions in config.neon:

Binary renderer

extensions:
    mjml: Surda\Mjml\DI\MjmlExtension
    mjml.renderer: Surda\Mjml\DI\MjmlBinaryRendererExtension

List of all configuration options:

mjml:
    debug: %debugMode%
    tempDir: %tempDir%/cache/latte
    templateFactory: \Surda\Mjml\TemplateFactory

mjml.renderer:
    renderer: \Surda\Mjml\Renderer\BinaryRenderer
    options:
        bin: mjml
        minify: FALSE
        validationLevel: strict
        beautify: TRUE

Install MJML

$ npm install -g mjml

API renderer

extensions:
    mjml: Surda\Mjml\DI\MjmlExtension
    mjml.renderer: Surda\Mjml\DI\MjmlApiRendererExtension

Minimal configuration:

mjml.renderer:
    options:
        applicationId: 'application-id'
        secretKey: 'secret-key'

List of all configuration options:

mjml:
    debug: %debugMode%
    tempDir: %tempDir%/cache/latte
    templateFactory: \Surda\Mjml\TemplateFactory

mjml.renderer:
    renderer: \Surda\Mjml\Renderer\ApiRenderer
    options:
        applicationId: 'application-id'
        secretKey: 'secret-key'
        uri: 'https://api.mjml.io/v1/render'

Usage

Template template.mjml

<mjml>
    <mj-body>
        <mj-section>
            <mj-column>
                <mj-image width="100px" src="https://mjml.io/assets/img/logo-small.png"></mj-image>
                <mj-divider border-color="#F45E43"></mj-divider>
                <mj-text font-size="20px" color="#F45E43" font-family="helvetica">Hello {$foo}</mj-text>
            </mj-column>
        </mj-section>
    </mj-body>
</mjml>
use Surda\Mjml\MjmlTemplateFactory;

class MailSender 
{
    /** @var MjmlTemplateFactory */
    private $mjmlTemplateFactory;
    
    /**
     * @param MjmlTemplateFactory $mjmlTemplateFactory
     */
    public function __construct(MjmlTemplateFactory $mjmlTemplateFactory)
    {
        $this->mjmlTemplateFactory = $mjmlTemplateFactory;
    }
    
    public function sendEmail(): void
    {
        $template = $this->mjmlTemplateFactory->create();
        $template->setFile('/path/to/template.mjml');
        $template->setParameters(['foo' => 'World']);

        $mail = new Message;
        $mail->setHtmlBody($template);
        
        // or

        $template = $this->mjmlTemplateFactory->create();

        $mail = new Message;
        $mail->setHtmlBody($template->renderToString('/path/to/template.mjml', ['foo' => 'World'])));

        // ...
    }
}

Mail

mail

Others

Only render *.latte template from *.mjml template

use Surda\Mjml\Engine;

class Convertor 
{
    /** @var Engine */
    private $engine;
    
    /**
     * @param Engine $engine
     */
    public function __construct(Engine $engine)
    {
        $this->engine = $engine;
    }
    
    public function convert(): void
    {
        $mjmlFile = '/path/to/template.mjml';
        $latteFile = $this->engine->renderLatteFile($mjmlFile);

        // or

        $mjmlFile = '/path/to/template.mjml';
        $latteFile = '/path/to/template.latte';
        $this->engine->renderLatteFile($mjmlFile, $latteFile);
    }
}

More in the MJML documentation.

mjml-nette's People

Contributors

surda avatar

Watchers

 avatar 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.