Replies: 6 comments 10 replies
-
|
Hello , @gremo I read you question and figure it out what is exactly your issue so just want to tell you that , As of my last knowledge update in September 2021, there might not be a dedicated Twig prettier plugin available to format Twig files directly using the Prettier tool. Prettier is primarily designed for formatting JavaScript, TypeScript, CSS, HTML, and other languages, but not specifically for Twig. However, there are potential workarounds you can explore to achieve a similar result: VSCode Extension with Prettier Support: If you are using Visual Studio Code (VSCode) as your code editor, there are extensions that integrate Prettier and support Twig files indirectly. For example, the "Prettier - Code formatter" extension can format multiple file types, including HTML and CSS, which are often used in conjunction with Twig templates. Myjdfaccount VSCode Extension for Twig Formatting: Some VSCode extensions are specifically designed for formatting Twig files. You can search for "Twig" or "Twig formatter" extensions in the VSCode Marketplace to find one that suits your needs. Integrate Prettier with Custom Scripts: You can create custom scripts or build systems that invoke Prettier's CLI (Command Line Interface) to format Twig files. This approach allows you to use Prettier for formatting in conjunction with other tools or your project's build process. Explore Other Tools: While Prettier is a widely used code formatter, there may be other dedicated Twig formatting tools or plugins available that can help you achieve the desired result. Keep in mind that the availability of tools and plugins may have changed since my last update. I recommend searching online or checking relevant developer communities and forums for any new updates, plugins, or extensions related to formatting Twig files with Prettier or other formatting tools. I hope my suggestion help you out Thank You . |
Beta Was this translation helpful? Give feedback.
-
|
Yes, you can configure the Prettier plugin to work specifically for Twig files by setting up a file-specific configuration. Here's how you can do it: Install the Prettier plugin for your code editor if you haven't already. For example, if you're using Visual Studio Code, install the "Prettier - Code formatter" extension. In your project's root directory, create a file named .prettierrc (or .prettierrc.json, .prettierrc.yaml, etc.) to define your Prettier configuration. In the .prettierrc file, specify the file-specific configuration for Twig files. For example, to configure Twig files to use a tab width of 4 spaces, the configuration could be: Copy Save the .prettierrc file. Now, when you format a Twig file using the Prettier plugin, it will use the specific configuration defined in the .prettierrc file for Twig files. Other file types will continue to use the default or global Prettier configuration. |
Beta Was this translation helpful? Give feedback.
-
|
The only way to make this work with Twig files is to use Prettier to format your .twig files, and Prettier sucks for Twig files. This is a pain in the butt because you can only use Prettier for twig if you:
For some odd reason they decided to release this plugin for Prettier, assuming that every coder out there uses it as their formatter :/ I've opened a discussion here yesterday to ask if they could possibly release a more universal approach, like a node package, to only sort the classes, so that people are free to use the formatter they want: #11830 Ma secondo me nemmeno lo leggeranno 😁 |
Beta Was this translation helpful? Give feedback.
-
|
Twig support would be great. In the meantime I've found that using the "prettier": {
"plugins": [
"@shopify/prettier-plugin-liquid",
"prettier-plugin-tailwindcss"
],
"overrides": [
{
"files": "*.twig",
"options": {
"parser": "liquid-html"
}
}
]
},Maybe using this module as a base to create a new prettier plugin for twig would be a good idea. |
Beta Was this translation helpful? Give feedback.
-
|
we're one step closer 🎉 This amazing person forked Trivago's The only remaining issue is that the TailwindCSS plugin for Prettier does not support it, so I've opened an issue here tailwindlabs/prettier-plugin-tailwindcss#254, and they're willing to add support, but the author of the fork needs to publish it as a separate package (more info inside the issue). I've now opened an issue there too hoping they can publish that package, you're very welcome to go star the fork and upvote the issues I've created ❤️ |
Beta Was this translation helpful? Give feedback.
-
|
@alessandro-newzoo that's a pretty good news! One question: does it work with utilities like |
Beta Was this translation helpful? Give feedback.
-
I'm not using Twig prettier plugins. Is there a way o make this plugin work for Twig files alone?
Beta Was this translation helpful? Give feedback.
All reactions