{"id":20377,"library":"prettier-plugin-jinja-template","title":"Prettier Plugin for Jinja Templates","description":"Prettier plugin for formatting Jinja (Jinja2) template files in HTML and other file types. Current stable version is 2.1.0. It runs as a Prettier plugin and requires Prettier v3+. It parses Jinja syntax mixed with HTML, respects Jinja block structure, and supports range ignores via HTML or Jinja comments. Key differentiators: dedicated Jinja parser (not a generic Liquid/Nunjucks plugin), supports Jinja's specific control flow (for, if, block, etc.), and is actively maintained. It does not format plain HTML or CSS/JS within templates unless paired with a second Prettier plugin like @prettier/plugin-html or prettier-plugin-go-template. TypeScript types are shipped.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/davidodenwald/prettier-plugin-jinja-template","tags":["javascript","prettier","plugin","template","html","jinja","jinja2","flask","typescript"],"install":[{"cmd":"npm install prettier-plugin-jinja-template","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-jinja-template","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-jinja-template","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime peer dependency; the plugin is loaded by Prettier and requires version ^3.0.0","package":"prettier","optional":false}],"imports":[{"note":"ESM and CJS both work via Prettier config; no direct JavaScript import of the plugin exists.","wrong":"Trying to import the plugin programmatically with require() or import, which is not supported—the plugin must be loaded via Prettier config or CLI --plugin flag.","symbol":"plugin (via Prettier config)","correct":"Use .prettierrc:\n{\n  \"plugins\": [\"prettier-plugin-jinja-template\"]\n}"},{"note":"The parser name is 'jinja-template', not 'jinja' or 'jinja2'.","wrong":"npx prettier --parser=jinja --write file.html -- wrong parser name, must be exactly 'jinja-template'","symbol":"Parser (jinja-template)","correct":"npx prettier --parser=jinja-template --write file.html"},{"note":"Use overrides to apply only to files containing Jinja templates; otherwise Prettier will fail to parse pure HTML/JS/CSS files.","wrong":"Setting parser: 'jinja-template' globally in .prettierrc without override, which will break formatting of non-Jinja files.","symbol":"Override (prettier config)","correct":"{\n  \"overrides\": [{\n    \"files\": \"*.html\",\n    \"options\": { \"parser\": \"jinja-template\" }\n  }]\n}"}],"quickstart":{"code":"npm install --save-dev prettier prettier-plugin-jinja-template\necho '{\n  \"plugins\": [\"prettier-plugin-jinja-template\"],\n  \"overrides\": [{\n    \"files\": \"*.html\",\n    \"options\": { \"parser\": \"jinja-template\" }\n  }]\n}' > .prettierrc\necho '<!DOCTYPE html>\n<html>\n<head>\n  <title>{% if title %}{{ title }}{% else %}Default{% endif %}</title>\n</head>\n<body>\n  <ul>\n  {% for item in items %}\n    <li>{{ item.name }}</li>\n  {% endfor %}\n  </ul>\n</body>\n</html>' > template.html\nnpx prettier --write template.html","lang":"typescript","description":"Installs Prettier and the plugin, configures .prettierrc with the Jinja parser override, creates a sample template, and formats it."},"warnings":[{"fix":"Upgrade to Node.js 18 or later.","message":"Dropped support for Node.js 14 and 16 in v2.0.0","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Remove any usage of quoteAttributes from .prettierrc; the option is no longer available.","message":"Removed quoteAttributes option in v2.0.0","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Chain multiple Prettier plugins or consider using prettier-plugin-go-template which handles HTML+Jinja together.","message":"The plugin only formats Jinja syntax; it does not format HTML, CSS, or JavaScript within templates. Use additional plugins like @prettier/plugin-html or prettier-plugin-go-template for full HTML formatting.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use explicit file paths with the plugin: npx prettier --plugin=prettier-plugin-jinja-template --parser=jinja-template --write file.html","message":"Using --stdin-filepath with the plugin may not work correctly in some versions; always specify the file path.","severity":"deprecated","affected_versions":">=1.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-jinja-template' and ensure the working directory contains the project root.","cause":"The plugin is not installed or not in node_modules.","error":"[error] Cannot find module 'prettier-plugin-jinja-template'"},{"fix":"Add 'parser: \"jinja-template\"' to .prettierrc overrides for *.html files, or use npx prettier --parser=jinja-template --write template.html","cause":"The parser is not set via override or --parser flag. Prettier defaults to HTML parser.","error":"[error] No parser could be inferred for file template.html"},{"fix":"Remove 'quoteAttributes' from .prettierrc or upgrade config to remove it.","cause":"Option was removed in v2.0.0 but still present in config.","error":"Error: Invalid option name: quoteAttributes"},{"fix":"Check Jinja syntax for errors, ensure all {% %} blocks are properly closed, and update to latest version.","cause":"This can occur when the plugin encounters a malformed Jinja expression or unexpected syntax, especially with empty expressions.","error":"TypeError: Cannot read properties of undefined (reading 'source')","affected_versions":">=1.3.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}