{"id":13594123,"url":"https://github.com/qferr/mjml-twig","last_synced_at":"2025-10-29T02:29:22.852Z","repository":{"id":39710922,"uuid":"252496677","full_name":"qferr/mjml-twig","owner":"qferr","description":"MJML extension for Twig","archived":false,"fork":false,"pushed_at":"2023-02-27T16:06:40.000Z","size":54,"stargazers_count":20,"open_issues_count":3,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T01:47:30.383Z","etag":null,"topics":["mjml","php","twig"],"latest_commit_sha":null,"homepage":"https://qferrer.medium.com/using-mjml-with-twig-cccea9af0086","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qferr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-04-02T15:39:12.000Z","updated_at":"2024-03-22T01:00:51.000Z","dependencies_parsed_at":"2024-01-16T22:18:22.374Z","dependency_job_id":"989c3378-4752-4386-88f1-fbaee9d5ee16","html_url":"https://github.com/qferr/mjml-twig","commit_stats":{"total_commits":15,"total_committers":4,"mean_commits":3.75,"dds":"0.19999999999999996","last_synced_commit":"3bf8db325fd95fcdfb860c174cbc2fb01104992d"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qferr%2Fmjml-twig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qferr%2Fmjml-twig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qferr%2Fmjml-twig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qferr%2Fmjml-twig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qferr","download_url":"https://codeload.github.com/qferr/mjml-twig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247997863,"owners_count":21030694,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mjml","php","twig"],"created_at":"2024-08-01T16:01:28.961Z","updated_at":"2025-10-29T02:29:17.810Z","avatar_url":"https://github.com/qferr.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"Twig MJML extension\n===================\n\nThis package is a Twig extension that provides the following:\n* mjml_to_html filter: processes a mjml email template.\n\n```twig\n{% apply mjml_to_html %}\n\u003cmjml\u003e\n    \u003cmj-body\u003e\n        \u003cmj-section\u003e\n            \u003cmj-column\u003e\n                \u003cmj-text\u003eHello {{ username }}\u003c/mj-text\u003e\n            \u003c/mj-column\u003e\n        \u003c/mj-section\u003e\n    \u003c/mj-body\u003e\n\u003c/mjml\u003e\n{% endapply %}\n```\n\nBecause we have two ways for rendering MJML to HML, the extension depends on a renderer:\n* **BinaryRenderer**: using the MJML library. You will have to provide the location of the MJML binary. Don’t forget to install it with the Node package manager.\n* **ApiRenderer**: using the MJML API. Nothing to install. You will have to provide the credentials to access of the API.\n\nThanks to the library [MJML in PHP](https://github.com/qferr/mjml-php) for make easier the integration of MJML in PHP. \nRead the article [Rendering MJML in PHP](https://medium.com/@qferrer/rendering-mjml-in-php-982d703aa703?source=friends_link\u0026sk=7c5553ae7fcfcdde889bdd3b776c90a9) for more informations.\n\nInstallation\n------------\n\n`composer require qferr/mjml-twig`\n\nUsage\n-----\n\n```php\n\u003c?php\nrequire_once 'vendor/autoload.php';\n\nuse \\Qferrer\\Mjml\\Renderer\\ApiRenderer;\nuse \\Qferrer\\Mjml\\Renderer\\BinaryRenderer;\nuse \\Qferrer\\Mjml\\Twig\\MjmlExtension;\n\n$loader = new \\Twig\\Loader\\FilesystemLoader(__DIR__ . '/templates');\n$twig = new \\Twig\\Environment($loader);\n\n$renderer = new BinaryRenderer(__DIR__ . '/node_modules/.bin/mjml');\n// $api = new \\Qferrer\\Mjml\\Http\\CurlApi('my-app-id','my-secret-key');\n// $renderer = new \\Qferrer\\Mjml\\Renderer\\ApiRenderer($api);\n$twig-\u003eaddExtension(new MjmlExtension($renderer));\n\n$html = $twig-\u003erender('newsletter.mjml.twig', [\n    'username' =\u003e 'Quentin'\n]);\n```\n\nYou can now start using MJML in any Twig template.\n\nIntegrating in Symfony\n----------------------\nRegister the MJML extension as a service and tag it with `twig.extension`.\n\n```yaml\n# config/services.yaml\nservices:\n  # Qferrer\\Mjml\\Http\\CurlApi:\n  #  arguments:\n  #     - '%env(MJML_APP_ID)%'\n  #     - '%env(MJML_SECRET_KEY)%'\n\n  # mjml_renderer:\n  #  class: Qferrer\\Mjml\\Renderer\\ApiRenderer\n  #  arguments:\n  #    - '@Qferrer\\Mjml\\Http\\CurlApi'\n\n  mjml_renderer:\n    class: Qferrer\\Mjml\\Renderer\\BinaryRenderer\n    arguments:\n      - '%kernel.project_dir%/node_modules/.bin/mjml'\n\n  Qferrer\\Mjml\\Twig\\MjmlExtension:\n    arguments: ['@mjml_renderer']\n    tags: ['twig.extension']\n```\n\nSource: [Using MJML with Twig](https://medium.com/@qferrer/using-mjml-with-twig-cccea9af0086?source=friends_link\u0026sk=0271c98a6225ff216cec5faefd6d7267)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqferr%2Fmjml-twig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqferr%2Fmjml-twig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqferr%2Fmjml-twig/lists"}