In my admin_controller.ex, I have a code to get all card types as shown below:
def index(conn, _params) do
cardTypes = MyApp.Repo.all(MyApp.CardTypes.CardType)
render(conn, "index.html", cardTypes: cardTypes)
end
How to get records order by card_type name in descending order
//index.html.eex, I have code as shown below:
<table class="table table-bordered" >
<tbody>
<% i = 1 %>
<%= for cardType <- @cardTypes do %>
<tr>
<td><%= i %></td>
<% card_type = cardType.card_type %>
<%= if card_type = "Income" do %>
<td class="text-center"><a href="admin/income-cards"><%= cardType.card_type %></a></td>
<% else %>
<td class="text-center"><a href="admin/expense-cards"><%= cardType.card_type %></a></td>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
I want to print the value of i as 1,2,3,4 and so on. Second I want to use if condition like
<%= if cond do %>
<%= elseif cond do %>
<%= elseif cond do %>
<% end %>
<% end %>
<% end %>
How to achieve this in phoenix templates