Case Empty in Web3 Json Array Output

hi, first im sorry if my grammar are messy, in here i have output which is from array of coin gecko

<%= hot_coins[“market_data”][“total_supply”]%>

in case some coin from coin gecko has unlimited supply and some other have limited supply, on my concent is , from unlimited supply it has no output or we can say it like empty, on that condition i want to create like

<% case / if empty hot_coins[“market_data”][“total_supply”] do %>
show the loopimage
<% else %>
// echo supply which i have here
<%= hot_coins[“market_data”][“total_supply”]%>

that makes me confused how to create condition if empty value.

Hello and welcome…

It’s possible to test for empty with is_nil.

But I would do like this…

<%= render_coins(hot_coins[“market_data”][“total_supply”]) %>

# then write the helper functions
def render_coins(nil) do
  # show loop image
def render_coins(coins) do

It has the advantage to clean up the template, and to use a simple pattern match for the render.

BTW: You can wrap your code with ``` to format it, like in Markdown,

i kind of find the solution

<%= if (@output[“market_data”][“total_supply”] != nil) do%>
<%= @output[“market_data”][“total_supply”] %> M
<%else %>

                  <% end %>

but it looks bad, did you have any advice for it?


i have found another solution using Enum.empty?() instead of != nil