Tailwind class in module constant not compiled?

If I put a part of class name in a module attribute, class name appears but CSS declarations won’t apply. I think Tailwind compiles before Phoenix does? It works fine if I just put them in the functions. Can I somehow use module attributes for classes?

  @black "dusk"
  @white "amber-50"

  # ...

  def theme(:normal) do
    [
      "bg-#{@white} dark:bg-#{@black}",
      "text-#{@black} dark:text-#{@white}"
    ]
  end
<!-- Classes don't apply the colours. -->
<body class="bg-amber-50 dark:bg-dusk text-dusk dark:text-amber-50 ...">
  ...
</body>

This is a common pitfall with tailwinds class detection:

3 Likes