-
Notifications
You must be signed in to change notification settings - Fork 187
unable to dynamically assign a color attribute #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You have to change the config/tailwind.config.js to look at your models directory as well, if that's where you keep the color_code. But I'd probably recommend extracting such a translation to a helper (which is already watched for tw classes). |
Thanks |
Creating a category helper is working, but only half way from my intended use case. In the helper I am having to explicitly add the tailwind attribute like so
What I am trying to do is to just change the color id in the attribute based on my categories. That way I can use the same
This way I would be able to add the class |
Yeah, that's not going to work. Tailwind needs the full class listed to be able to pick it up. You'll need to duplicate the color. |
Usually I create a dummy page (not accessible) with a tag / class for all class names I want them to be available ..
|
Or a create my own custom tags using tailwind classes via @apply .. and use these custom names dynamically |
Great idea/work around |
Having an issue coloring some title text.
I have an h2 tag that gets assigned a color based on the objects category ID, something like this
<h2 class="text-<%= category.color_code %>">Title</h2>
Then I have a method in my Category model that looks like this
I'm using the bin/dev method for tailwindcss:watch
When loading the object onto the page and after II inspect my code in the browser it is rendered correctly,
<h2 class="text-rose-400">Title</h2>
but the title is not colored.
Looking at the build in
app/assets/builds/tailwind.css
The colors are not included, so it seems that the css is being built before html/erb is.
Everything works fine if I manually put a color attribute in.
The text was updated successfully, but these errors were encountered: