Registry / prettier-plugin-twig-enhancements

prettier-plugin-twig-enhancements

JSON →
library1.0.1jsnpmunverified

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.

npm install prettier-plugin-twig-enhancements
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-TW
P
prettier-plugin-twig-enhancements
javascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
// No default export; plugin is automatically loaded via Prettier config
import prettierPluginTwigEnhancements from 'prettier-plugin-twig-enhancements'
This is not a Prettier plugin itself but an extension for prettier-plugin-twig-melody; it is loaded via twigMelodyPlugins config.
Plugin
// No named exports; configure via .prettierrc
const Plugin = require('prettier-plugin-twig-enhancements')
The package exports nothing; it adds a plugin to the twigMelodyPlugins array.
config
// add to .prettierrc: { "twigMelodyPlugins": ["node_modules/prettier-plugin-twig-enhancements"] }
// Incorrect: setting it as a Prettier plugin
Must be under twigMelodyPlugins, not plugins.

Install peer dependencies, configure .prettierrc, and format a Nunjucks template with the enhancements.

// Install peer deps and this plugin npm install --save-dev prettier@^2.1.2 prettier-plugin-twig-melody@^0.4.6 prettier-plugin-twig-enhancements@^1.0.1 // .prettierrc { "twigMelodyPlugins": ["node_modules/prettier-plugin-twig-enhancements"], "printWidth": 80, "tabWidth": 2 } // Run on .njk file npx prettier --write template.njk
Debug
Known issues
breakingv1.0.0 removed frontmatter support — if you relied on that for YAML frontmatter, you need to find an alternative.
fix
Use a different tool like nunjucks-frontmatter-preprocessor before formatting.
affects: >=1.0.0
deprecatedThe author states the Twig plugin is not well compatible with Nunjucks, making this enhancement less useful.
fix
Consider using a Nunjucks-specific formatter like prettier-plugin-nunjucks or unformatted.
affects: >=0.1.1
gotchaThis plugin is not a Prettier plugin; it's a plugin for prettier-plugin-twig-melody. You must configure it under twigMelodyPlugins, not plugins.
fix
Use twigMelodyPlugins array in .prettierrc.
affects: >=0.1.1
gotchaRequires specific versions of peer deps: prettier ^2.1.2 and prettier-plugin-twig-melody ^0.4.6. Newer versions may not work.
fix
Lock peer deps to those versions.
affects: >=0.1.1
gotchav1.0.1 changed behavior for empty HTML elements: now keeps <div></div> on one line instead of introducing a newline.
fix
If you prefer the old behavior, pin to v1.0.0.
affects: >=1.0.1
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-twig-enhancements'
The plugin is not installed or not in node_modules.
fix
Run npm install --save-dev prettier-plugin-twig-enhancements.
Invalid twigMelodyPlugins: Expected a list of strings
The plugin path is incorrect or configured under plugins instead of twigMelodyPlugins.
fix
Use "twigMelodyPlugins": ["node_modules/prettier-plugin-twig-enhancements"] in .prettierrc.
Prettier version 3.x is not supported by prettier-plugin-twig-melody
Peer deps require prettier ^2.1.2.
fix
Downgrade prettier to 2.x: npm install --save-dev prettier@^2.1.2.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
prettierrequiredpeer dependency
prettier-plugin-twig-melodyrequiredpeer dependency, this plugin extends it
Agent activity
2 hits · last 30 days
node
2
Resources
prettier-plugin-twig-enhancements — npm install prettier-plugin-twig-enhancements · libregistry