简体   繁体   中英

Single quotes cause LiveView template processing error

I want to use the following Tainwind classes in my Phoenix LiveView template:

<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?

This problem can be worked around by using a sigil instead of the usual binary string:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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