DEV Community

Discussion on: How to keep Tailwind DRY

Collapse
 
owenmelbz profile image
Owen Melbourne • Edited

Good article, with some nice examples!

It would be beneficial to people still learning to remove any loaded content such as "You might be able to get it to work with PHP templates, but I'd say this method is best for JavaScript" - You can absolutely and 100% do this with PHP with great ease, and other languages like Ruby, .Net etc etc etc - Remember they've been around longer and more mature so can handle this stuff in their sleep, we do it every single day, and it is in fact easier as those languages have less boilerplate than React/Vue/etc.

Collapse
 
charliejoel profile image
Charlie Joel • Edited

I hear you, I don't think I explained my reasoning very well there!

You're right, you can definitely get this working with PHP and any other language using templates. The reason I prefer to use JS is

  1. Control over styles isn't limited to the backend - you could make a button add/remove a class, for example, which takes longer to do with inline JS.
  2. You can keep everything (JS, HTML, CSS) in one area. I know you could just make a tag in PHP, but that JS would be in the global scope without taking extra steps and (to me) it feels a little clunky.

With that said, I can already see holes in my arguments - at this point it's more to do with my personal preference/experience. I do encourage working like this in non-JS environments, but I'm not an expert in that area!

Some comments have been hidden by the post's author - find out more