SymfonyCasts / tailwind-bundle

Delightful Tailwind Support for Symfony + AssetMapper
https://symfony.com/bundles/TailwindBundle/current/index.html
MIT License
84 stars 20 forks source link

Render Twig first #72

Closed psion closed 1 month ago

psion commented 1 month ago

I have some custom Twig filters that have broken my tailwind build and left some styles out of the final CSS. Is there any plans to have an option to use rendered Twig instead of just the twig files themselves when building.

bocharsky-bw commented 1 month ago

Hm, custom Twig filters should not be a problem if they're registered in the Twig configuration properly. How do you register those filters? Do them work only for specific Twig environment, i.e. not globally?

psion commented 1 month ago

My Twig filters work as a standard extension within Symfony, and it should work globally. The filter is supposed to take the url of an image, look in the db for an image with the slug used, and replace the url with the slugged image, and if there is no slug in the db return what was originally being filtered. When I have the filter in place, tailwind:build completely ignores it and I am now lacking a background image.

bocharsky-bw commented 1 month ago

I'm not sure I understand it completely. You're talking about the CSS and Twig. Do you have some <style></style> tags inside your Twig templates where you write down some hardcoded CSS? Otherwise I can't understand how you use Twig filter inside your CSS files

psion commented 1 month ago

The html has a class tag with the background image url as part of the styling. <section class="relative bg-[url({% apply banner_image %}https://images.unsplash.com/photo-1604014237800-1c9102c219da?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1770&q=80{% endapply %})] bg-cover bg-center bg-no-repeat" > When I have the filter banner_image in place, the tailwind build completely ignores it.

bocharsky-bw commented 1 month ago

Hm, I see it's a dynamic class, probably the ideas in this issue will help you, please take a look: https://github.com/SymfonyCasts/tailwind-bundle/issues/51

Or you could probably rewrite your code and instead of dynamic Tailwind class use style HTML property on that tag to set the proper dynamic background on that element.

psion commented 1 month ago

I see what you mean with the dynamic class and I'm looking at a rewrite on it. Still a bit flummoxed on why the filter got ignored completely.