{"id":20447,"library":"prettier-plugin-twig-melody","title":"Prettier Plugin for Twig/Melody","description":"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).","status":"deprecated","version":"0.4.6","language":"javascript","source_language":"en","source_url":"https://github.com/trivago/prettier-plugin-twig-melody","tags":["javascript"],"install":[{"cmd":"npm install prettier-plugin-twig-melody","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-twig-melody","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-twig-melody","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; the plugin is designed to be used with Prettier","package":"prettier","optional":false},{"reason":"Included in the plugin, not a separate dependency","package":"@m59/verbosely","optional":true}],"imports":[{"note":"This is a Prettier plugin, not a library. It is loaded automatically or via the plugins array in .prettierrc. No direct import is needed.","wrong":"import prettierPluginTwigMelody from 'prettier-plugin-twig-melody'","symbol":"plugin","correct":"Use via Prettier configuration: plugins: [\"prettier-plugin-twig-melody\"]"},{"note":"Options are set in Prettier configuration, not passed programmatically.","wrong":"Passing options via Prettier API without proper configuration","symbol":"options","correct":"Add options to .prettierrc: { \"twigSingleQuote\": true, \"twigPrintWidth\": 80 }"},{"note":"The plugin is not a standalone module; it must be used through Prettier's format function with the plugin specified.","wrong":"require('prettier-plugin-twig-melody') directly expecting a function","symbol":"require with Prettier API","correct":"const prettier = require('prettier'); prettier.format(code, { parser: 'twig', plugins: ['prettier-plugin-twig-melody'] })"}],"quickstart":{"code":"# Install\nnpm install --save-dev prettier prettier-plugin-twig-melody\n\n# Format a .twig file via CLI\nnpx prettier --write \"**/*.twig\"\n\n# Programmatic usage\nconst prettier = require('prettier');\nconst code = `{% for item in items %}\n    <li>{{ item.name }}</li>\n{% endfor %}`;\nprettier.format(code, {\n  parser: 'twig',\n  plugins: ['prettier-plugin-twig-melody'],\n  twigSingleQuote: true,\n  twigPrintWidth: 80\n}).then(result => console.log(result));","lang":"javascript","description":"Demonstrates installing the plugin, formatting via CLI, and using the Prettier API with the plugin."},"warnings":[{"fix":"Consider alternatives like @shopify/prettier-plugin-twig or prettier-plugin-twig (community fork).","message":"This plugin is no longer maintained. The GitHub repository has been archived.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Set plugins: ['./node_modules/prettier-plugin-twig-melody'] in your Prettier config.","message":"The plugin must be explicitly added to the `plugins` array in .prettierrc for editor integration if not auto-loaded.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Correct: prettier.format(code, { parser: 'twig', plugins: ['prettier-plugin-twig-melody'] })","message":"When using the Prettier API, the plugin must be passed in the `plugins` array of the options object, not as a separate argument.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure the string follows the pattern 'openingTag, ..., closingTag' with commas separating tags.","message":"The `twigMultiTags` option requires the order of tags to be correct: the opening tag first, the closing tag last, e.g., 'nav,endnav' not 'endnav,nav'.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Upgrade Node.js to version 6 or later.","message":"Node.js >=6 required. The plugin uses features not available in older Node versions.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install --save-dev prettier prettier-plugin-twig-melody","cause":"Plugin not installed or not in node_modules","error":"Cannot find module 'prettier-plugin-twig-melody'"},{"fix":"Add the plugin to the plugins array in .prettierrc or pass it via CLI with --plugin=prettier-plugin-twig-melody","cause":"Prettier is not using the plugin to parse .twig files","error":"Error: No parser could be inferred for file: example.twig"},{"fix":"Check the Twig template for syntax errors or unsupported constructs. Ensure the template is valid Twig/Melody.","cause":"Plugin cannot parse a malformed Twig template","error":"TypeError: Cannot read property 'type' of undefined"},{"fix":"Add options to .prettierrc or pass them in the format call: prettier.format(code, { twigSingleQuote: true, plugins: [...] })","cause":"Options must be set in Prettier configuration file or passed correctly via API","error":"Options were not applied: twigSingleQuote still false"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}