{"id":20446,"library":"prettier-plugin-twig-enhancements","title":"prettier-plugin-twig-enhancements","description":"A plugin for prettier-plugin-twig-melody that adds subtle formatting enhancements for Twig/Nunjucks templates. Current stable version is 1.0.1. It improves HTML element formatting to be more like Prettier (e.g., keeping short elements on one line, breaking long attributes) and prints empty {% block %} statements on a single line. No new releases since January 2023; the project is in maintenance mode as the author notes the Twig plugin is not well compatible with Nunjucks. Peer dependencies: prettier ^2.1.2 and prettier-plugin-twig-melody ^0.4.6. Key differentiator: addresses limitations of the base plugin for Nunjucks frontmatter and HTML formatting.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/mubaraqwahab/prettier-plugin-twig-frontmatter","tags":["javascript","prettier","plugin","prettier-plugin-twig-melody","nunjucks","frontmatter"],"install":[{"cmd":"npm install prettier-plugin-twig-enhancements","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-twig-enhancements","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-twig-enhancements","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency","package":"prettier","optional":false},{"reason":"peer dependency, this plugin extends it","package":"prettier-plugin-twig-melody","optional":false}],"imports":[{"note":"This is not a Prettier plugin itself but an extension for prettier-plugin-twig-melody; it is loaded via twigMelodyPlugins config.","wrong":"import prettierPluginTwigEnhancements from 'prettier-plugin-twig-enhancements'","symbol":"default","correct":"// No default export; plugin is automatically loaded via Prettier config"},{"note":"The package exports nothing; it adds a plugin to the twigMelodyPlugins array.","wrong":"const Plugin = require('prettier-plugin-twig-enhancements')","symbol":"Plugin","correct":"// No named exports; configure via .prettierrc"},{"note":"Must be under twigMelodyPlugins, not plugins.","wrong":"// Incorrect: setting it as a Prettier plugin","symbol":"config","correct":"// add to .prettierrc:\n{\n  \"twigMelodyPlugins\": [\"node_modules/prettier-plugin-twig-enhancements\"]\n}"}],"quickstart":{"code":"// Install peer deps and this plugin\nnpm install --save-dev prettier@^2.1.2 prettier-plugin-twig-melody@^0.4.6 prettier-plugin-twig-enhancements@^1.0.1\n\n// .prettierrc\n{\n  \"twigMelodyPlugins\": [\"node_modules/prettier-plugin-twig-enhancements\"],\n  \"printWidth\": 80,\n  \"tabWidth\": 2\n}\n\n// Run on .njk file\nnpx prettier --write template.njk","lang":"javascript","description":"Install peer dependencies, configure .prettierrc, and format a Nunjucks template with the enhancements."},"warnings":[{"fix":"Use a different tool like nunjucks-frontmatter-preprocessor before formatting.","message":"v1.0.0 removed frontmatter support — if you relied on that for YAML frontmatter, you need to find an alternative.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Consider using a Nunjucks-specific formatter like prettier-plugin-nunjucks or unformatted.","message":"The author states the Twig plugin is not well compatible with Nunjucks, making this enhancement less useful.","severity":"deprecated","affected_versions":">=0.1.1"},{"fix":"Use twigMelodyPlugins array in .prettierrc.","message":"This plugin is not a Prettier plugin; it's a plugin for prettier-plugin-twig-melody. You must configure it under twigMelodyPlugins, not plugins.","severity":"gotcha","affected_versions":">=0.1.1"},{"fix":"Lock peer deps to those versions.","message":"Requires specific versions of peer deps: prettier ^2.1.2 and prettier-plugin-twig-melody ^0.4.6. Newer versions may not work.","severity":"gotcha","affected_versions":">=0.1.1"},{"fix":"If you prefer the old behavior, pin to v1.0.0.","message":"v1.0.1 changed behavior for empty HTML elements: now keeps <div></div> on one line instead of introducing a newline.","severity":"gotcha","affected_versions":">=1.0.1"}],"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-plugin-twig-enhancements.","cause":"The plugin is not installed or not in node_modules.","error":"Cannot find module 'prettier-plugin-twig-enhancements'"},{"fix":"Use \"twigMelodyPlugins\": [\"node_modules/prettier-plugin-twig-enhancements\"] in .prettierrc.","cause":"The plugin path is incorrect or configured under plugins instead of twigMelodyPlugins.","error":"Invalid twigMelodyPlugins: Expected a list of strings"},{"fix":"Downgrade prettier to 2.x: npm install --save-dev prettier@^2.1.2.","cause":"Peer deps require prettier ^2.1.2.","error":"Prettier version 3.x is not supported by prettier-plugin-twig-melody"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}