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”]%>
<%end%>
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
end
def render_coins(coins) do
...
end
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 %>
UNLIMITED
<% end %>
but it looks bad, did you have any advice for it?
SOLVED
i have found another solution using Enum.empty?() instead of != nil