prettier-twig-tailwind-format Tailwind Templates

Prettier Twig Tailwind Format

Examples of formatting Twig templates with Tailwind CSS classes using Prettier and custom plugins

Prettier + Twig + Tailwind CSS Formatting

πŸ’… This repository demonstrates how to format *.html.twig (*.twig) files that include Tailwind CSS classes using Prettier and relevant plugins.

✨ Purpose

πŸ“ Files

The templates folder contains 5 example files:

[!TIP] You can format anywhere.raw.html.twig and zackad.raw.html.twig using pnpm format:fix command or just by opening the file and saving it.

βš™οΈ Setup

This project uses the pnpm package manager.

[!NOTE] If you haven’t used pnpm before, check out the pnpm installation guide.

🧰 Install Dependencies

pnpm install

πŸͺ› Format Files

  • Check formatting:

    pnpm format
    
  • Fix formatting:

    pnpm format:fix
    

πŸ›  Prettier Configuration

The configuration applies specific plugins based on filenames:

[!NOTE] These overrides are defined in prettier.config.mjs.

🧩 VS Code Integration

This project includes VS Code extension recommendations in .vscode/extensions.json:

  • bradlc.vscode-tailwindcss – Optional: Provides intelligent Tailwind CSS support in VS Code (class name autocomplete, linting, etc.)
  • esbenp.prettier-vscode – Required: Integrates Prettier into VS Code for consistent formatting

🧾 VS Code Workspace Settings

The project contains workspace-specific settings in .vscode/settings.json that override your global VS Code preferences:

{
  "[html]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[twig]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  // Adjust if using a Twig-specific VS Code extension
  "files.associations": {
    "*.html.twig": "html",
    "*.twig": "html"
  },
  // Optional, see https://github.com/prettier/prettier-vscode?tab=readme-ov-file#prettierdocumentselectors
  // "prettier.documentSelectors": ["*.html.twig", "*.twig"],
  "prettier.enable": true
}

πŸ“„ License

MIT License

Top categories

Loading Svelte Themes