A Prettier plugin that formats .twig, .html.twig, and .melody.twig files using the Melody parser. Version 0.4.6 is the latest stable release. It integrates with Prettier to provide consistent formatting for Twig templates used in Melody-based UI frameworks. Key differentiators include support for custom Twig extensions via twigMelodyPlugins, multi-tag handling (e.g., nav/endnav), and options to follow Symfony coding standards. It has several configuration options (twigSingleQuote, twigPrintWidth, twigAlwaysBreakObjects, etc.) but is not actively maintained (last release 2021, repository archived).
npm install prettier-plugin-twig-melodyVerified import paths — ran on the pinned version, not inferred.
Demonstrates installing the plugin, formatting via CLI, and using the Prettier API with the plugin.
Consider alternatives like @shopify/prettier-plugin-twig or prettier-plugin-twig (community fork).
Set plugins: ['./node_modules/prettier-plugin-twig-melody'] in your Prettier config.
Correct: prettier.format(code, { parser: 'twig', plugins: ['prettier-plugin-twig-melody'] })Ensure the string follows the pattern 'openingTag, ..., closingTag' with commas separating tags.
Upgrade Node.js to version 6 or later.
Run npm install --save-dev prettier prettier-plugin-twig-melody
Add the plugin to the plugins array in .prettierrc or pass it via CLI with --plugin=prettier-plugin-twig-melody
Check the Twig template for syntax errors or unsupported constructs. Ensure the template is valid Twig/Melody.
Add options to .prettierrc or pass them in the format call: prettier.format(code, { twigSingleQuote: true, plugins: [...] })