能否无需下载重建源码,创建MJML自定义基础及图库板块模板?
Answer
Absolutely! You can create custom templates for MJML's "Basics" and "Gallery" sections without copying existing projects or rebuilding from source—here's how to do it based on the MJML tool you're using:
For the MJML Desktop App
This is the simplest way to add custom templates directly to the app's interface:
- Find your MJML user templates directory:
- Windows:
C:\Users\[YourUsername]\AppData\Roaming\MJML\templates - macOS:
~/Library/Application Support/MJML/templates - Linux:
~/.config/MJML/templates
- Windows:
- Inside this folder, you’ll see subfolders like
basicsandgallery. Drop your custom.mjmltemplate files into the corresponding subfolder. - Restart the MJML app, and your custom templates will appear in the "Basics" or "Gallery" when starting a new project.
For MJML CLI/Team Workflows
If you’re using MJML via the command line or integrating into a team pipeline:
- Create a dedicated folder (e.g.,
./mjml-team-templates) in your shared project to store standardized base templates. - When starting a new email, use the
--templateflag to reference your custom template directly:mjml --template ./mjml-team-templates/weekly-newsletter-base.mjml new-newsletter.mjml - To make it even easier for your team, add a script to your
package.jsonthat scaffolds new projects with your templates:{ "scripts": { "new-email": "mjml --template ./mjml-team-templates/team-base.mjml src/new-email.mjml" } }
Pro Tips for Your Team
- Add clear placeholders: Include comments or variable placeholders (like
{{hero-title}},{{footer-contact}}) so colleagues can swap in content without rewriting layout code. - Label template use cases: Add a comment at the top of each template explaining its purpose (e.g.,
* Use this for product launch emails with a single CTA button *) to help the team pick the right template fast. - Version control templates: Store your template library in your team’s Git repo so everyone has access to the latest versions and can contribute improvements.
This approach keeps your templates integrated with MJML’s workflow without touching core source code, making it seamless for your team to start new projects with your standardized setup.
内容的提问来源于stack exchange,提问作者JCoulam
相关产品推荐
相关产品推荐

