Registry / devops / prettier-plugin-twig-melody

prettier-plugin-twig-melody

JSON →
library0.4.6jsnpmunverified

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-melody
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-TW
P
prettier-plugin-twig-melody
devopsjavascriptv0.4.6
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.

plugin
Use via Prettier configuration: plugins: ["prettier-plugin-twig-melody"]
import prettierPluginTwigMelody from 'prettier-plugin-twig-melody'
This is a Prettier plugin, not a library. It is loaded automatically or via the plugins array in .prettierrc. No direct import is needed.
options
Add options to .prettierrc: { "twigSingleQuote": true, "twigPrintWidth": 80 }
Passing options via Prettier API without proper configuration
Options are set in Prettier configuration, not passed programmatically.
require with Prettier API
const prettier = require('prettier'); prettier.format(code, { parser: 'twig', plugins: ['prettier-plugin-twig-melody'] })
require('prettier-plugin-twig-melody') directly expecting a function
The plugin is not a standalone module; it must be used through Prettier's format function with the plugin specified.

Demonstrates installing the plugin, formatting via CLI, and using the Prettier API with the plugin.

# Install npm install --save-dev prettier prettier-plugin-twig-melody # Format a .twig file via CLI npx prettier --write "**/*.twig" # Programmatic usage const prettier = require('prettier'); const code = `{% for item in items %} <li>{{ item.name }}</li> {% endfor %}`; prettier.format(code, { parser: 'twig', plugins: ['prettier-plugin-twig-melody'], twigSingleQuote: true, twigPrintWidth: 80 }).then(result => console.log(result));
Debug
Known issues
deprecatedThis plugin is no longer maintained. The GitHub repository has been archived.
fix
Consider alternatives like @shopify/prettier-plugin-twig or prettier-plugin-twig (community fork).
affects: >=0.0.0
gotchaThe plugin must be explicitly added to the `plugins` array in .prettierrc for editor integration if not auto-loaded.
fix
Set plugins: ['./node_modules/prettier-plugin-twig-melody'] in your Prettier config.
affects: >=0.0.0
gotchaWhen using the Prettier API, the plugin must be passed in the `plugins` array of the options object, not as a separate argument.
fix
Correct: prettier.format(code, { parser: 'twig', plugins: ['prettier-plugin-twig-melody'] })
affects: >=0.0.0
gotchaThe `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'.
fix
Ensure the string follows the pattern 'openingTag, ..., closingTag' with commas separating tags.
affects: >=0.0.0
gotchaNode.js >=6 required. The plugin uses features not available in older Node versions.
fix
Upgrade Node.js to version 6 or later.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-twig-melody'
Plugin not installed or not in node_modules
fix
Run npm install --save-dev prettier prettier-plugin-twig-melody
Error: No parser could be inferred for file: example.twig
Prettier is not using the plugin to parse .twig files
fix
Add the plugin to the plugins array in .prettierrc or pass it via CLI with --plugin=prettier-plugin-twig-melody
TypeError: Cannot read property 'type' of undefined
Plugin cannot parse a malformed Twig template
fix
Check the Twig template for syntax errors or unsupported constructs. Ensure the template is valid Twig/Melody.
Options were not applied: twigSingleQuote still false
Options must be set in Prettier configuration file or passed correctly via API
fix
Add options to .prettierrc or pass them in the format call: prettier.format(code, { twigSingleQuote: true, plugins: [...] })
Upgrade
Version history
0.4.6latest on npm
Audit
Dependencies
prettierrequiredPeer dependency; the plugin is designed to be used with Prettier
@m59/verboselyoptionalIncluded in the plugin, not a separate dependency
Agent activity
8 hits · last 30 days
node
8
Resources
prettier-plugin-twig-melody — npm install prettier-plugin-twig-melody · libregistry