I'm relatively new to Tailwind and using it with a custom Shopify theme. I installed Tailwind using the Tailwind CLI, and all static classes work fine.
However, I'm having trouble when trying to use Liquid variables inside Tailwind utility classes. I understand that Tailwind compiles before Liquid runs, but I want to clarify whether there's a better way to handle this.
The code that doesn't work, but what I am trying to achieve:
<!-- I tried dynamically setting max-width with a liquid variable -->
<div class="max-w-[{{ settings.page_width }}px]">
Content here
</div>
In the browser, this correctly renders as:
<div class="max-w-[1400px]">Content here</div>
…but Tailwind doesn’t apply the style because max-w-[1400px] wasn’t in the source when Tailwind compiled the CSS.
What works instead:
<style>
:root {
--page-width: {{ settings.page_width }} /* 1400px */
}
.page-width {
max-width: var(--page-width);
}
</style>
<div class="page-width">
Content here
</div>
My Question:
Is there any way to get Tailwind to apply styles for class names that use dynamic Liquid values like {{ settings.page_width }} — without manually safelisting every possible value in tailwind.config.js?
Or would I need to use a mix of tailwind and a 'vanilla' css file to handle those variables?
Thanks in advance.
liquid-? Then, tailwind can use them asmax-w-[--liquid-page-width]. Though at this point I would prefer to just mix Tailwind with the vanila htmlstyle.