简体   繁体   English

单引号导致 LiveView 模板处理错误

[英]Single quotes cause LiveView template processing error

I want to use the following Tainwind classes in my Phoenix LiveView template:我想在我的 Phoenix LiveView 模板中使用以下 Tainwind 类:

<div class="before:content-['Not_Hovering'] hover:before:content-['Hovering']">
  <!-- ... -->
</div>

But the single quotes are not processed correctly, and result in the following error:但是单引号没有被正确处理,导致如下错误:

no function clause matching in Phoenix.LiveView.Engine.analyze_list/4

    The following arguments were given to Phoenix.LiveView.Engine.analyze_list/4:
    
        # 1
        "&#39;"
    
        # 2
        {:restricted, %{}}
    
        # 3
        %{[:default_avatar] => true, [:groups] => true, [:myself] => true}
    
        # 4
        ["before:content-[", []]
    
    Attempted function clauses (showing 2 out of 2):
    
        defp analyze_list([31m[head | tail][0m, [22mvars[0m, [22massigns[0m, [22macc[0m)
        defp analyze_list([31m[][0m, [22mvars[0m, [22massigns[0m, [22macc[0m)

What can I do to use single quotes in the class string of a LiveView template, so that I can use these Tailwind classes?如何在 LiveView 模板的类字符串中使用单引号,以便可以使用这些 Tailwind 类?

This problem can be worked around by using a sigil instead of the usual binary string:这个问题可以通过使用 sigil 而不是通常的二进制字符串来解决:

<div class={~s"before:content-['Not_Hovering'] hover:before:content-['Hovering']"}>
  <!-- ... -->
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM