The 'prettier-plugin-tailwindcss' plugin cannot be used with PHP templates #17406
Replies: 2 comments
-
You're absolutely right—getting Prettier + TailwindCSS class sorting to work seamlessly in PHP templates is a big challenge, and it's something that many WordPress and PHP developers struggle with. Since PHP templates mix logic () with markup, Prettier and its plugins often fail to parse them correctly. Finding a proper solution is crucial because Tailwind's class sorting is a game-changer for maintainability, and PHP (especially WordPress) still powers a massive portion of the web. Right now, Blade templates seem to have better support, but PHP templates deserve the same treatment. Hopefully, the community or plugin maintainers will address this gap soon! |
Beta Was this translation helpful? Give feedback.
-
I'm with you on this, issue is very real. Isn't formatting php templates correctly (like the php block indentation), which is frustrating given how popular php and WP are. It would be great to see a solution addressing this |
Beta Was this translation helpful? Give feedback.
-
Hi.
The issue is that I was not able to get the 'prettier-plugin-tailwindcss' plugin does its work with PHP templates. I tried the '@prettier/plugin-php' and other variants.
I understand that Tailwind is more focused on new type of views (React, Vue, etc.) But PHP as still alive as well as WP with its 43.5% of all websites. I would appreciate an explanation of roots of my issue and perhaps there are ways to solve it. The same issue faced other my friends WP developers. I think there are a lot of developers with the same issue. It's good to have en explanation. Or maybe I don't see an elephant in the room.
Prerequisites:
<?php ?>
or<?= ?>
);When we use Tailwind the automatic ordering of classes is crucial for comfortable work as well as formatting of tag attributes. The Tailwind team created the 'prettier-plugin-tailwindcss' plugin for that. I haven't found the way to make it work with PHP templates. Except of the ugly hack to use the '@shufo/prettier-plugin-blade' instead of the '@prettier/plugin-php' for templates.
PHP template is not HTML
I already know that PHP template is not in compliance with HTML and it can't be parsed well until PHP tags are processed. It seems to be an unsolvable issue with no solutions. And a shot answer is "We can't use the 'plugin-php' for PHP templates". The HTML parser doesn't work too with PHP templates.
If it's impossible why something very similar works?
In that case why the '@prettier/plugin-php' works on 95% well with PHP templates? A Blade templates is pretty similar to a PHP one. With this plugin the 'prettier-plugin-tailwindcss' plugin works well and sorts classes. The only real issue that I currently have is it does not add indent for nested PHP tags, for example:
Here is the Pettier config (simplified part) that can somehow work:
Open questions
There is any solution to make the plugin work with PHP templates?
Or more general, how to auto-format Tailwind PHP templates well?
Beta Was this translation helpful? Give feedback.
All reactions