<.funcomponent :if, do: , else: /> inside a component tag don't work's!

I was thinking to convert this code:

<%= if @is_playing do %>
   <.icon name="hero-pause-circle-solid" />
<% else %>
   <.icon name="hero-play-circle-solid" />
<% end %> 

to this:

<.icon :if={@is_playing, do: name="hero-pause-circle-solid", else: name="hero-play-circle-solid"} />

and complains to this:

** (SyntaxError) lib/rld_live_view_studio_web/live/presence_live.ex:51:30: syntax error before: ','
    |
 51 | @is_playing, do: name="hero-pause-circle-solid", else: name="hero-play-circle-solid"
    |            ^

It has some way to do this?

<.icon name={if(@is_playing, do: "hero-pause-circle-solid", else: "hero-play-circle-solid")} />

:if is a directive that decides if the component will be rendered or not.

3 Likes

it worked, thank you @sodapopcan!

1 Like