musqsim's avatar

Parse HTML Content with tailwind classes into blade views

Hello, guys,

Using Laravel 10 + Vite + Tailwind

I'm just starting using Tailwind and seems great, except in one point.

In my blade view, I access to a custom attribute with specific tailwind classes.

Example: {!! $s->display_session_status !!}

this will return the following: '<span class="rounded-full px-3 bg-green-300 text-black inline-block">Efetuada</span>'

In this example, "text-black" doesn't load tailwind properties, and it happens in several other random attributes... Some load, other doesn't.

check the following image: https://ibb.co/t4s0ZcS

Do you guys know something about this and how to resolve?

Thanks

0 likes
4 replies
musqsim's avatar

@coni Hi, but those are Tailwind default classes used directly in blade templates with no problems. But when "injected" form my model attributes, some load and some doesn't.

musqsim's avatar

But Yes, "safelist" do the job, which odd, but anyways, thank you @coni!

1 like
richardhulbert's avatar

The thing to remember about Tailwind is that it builds the CSS based on what it finds in your code. You can point to where it should look in the tailwind.config file in the root of your project. Where things go wrong is where you are concatenating so for instance if you have dynamic classes (from a database) then Tailwind has no concept of those so they are omitted.

as @coni says you can use the safelist but this can soon get out of hand and you might end up with a large CSS file.

Please or to participate in this conversation.