Compare string with if-else in phoenix .heex template

Hi elixir members,

          <%= if cashflow_entry.entry_type == "income" do %>
            SVG for income
          <% else %>
            SVG for expense
          <% end %>

but the above code always show “SVG for expense” while the entry_type is “income”.

Coming from python django, as a newbie, how do i compare this?

more info,
in schema, entry_type is an enum like below.

field :entry_type, Ecto.Enum, values: [:income, :expense]
1 Like

Enum has atom values not string values.


ah i see!

how do we compare with atom?

<%= if cashflow_entry.entry_type == :income do %>

like this?

1 Like


I believe Python does not have an equivalent for atoms/symbols, but your usage of atoms is correct here. :slight_smile:

1 Like

according to my experience level, nope, there are only CONSTANT and string coming from db. :smiley: