Phoenix template customization

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

If only class is different then I would create function in view:

defp card_class(%{card_type: "Income"}), do: "admin/income-cards"
defp card_class(%{card_type: "Expense"}), do: "admin/expense-cards"
defp card_class(_), do: "admin/other-cards"

Alternatively if the naming scheme is that class is starting with lowercase card_type then you can do:

defp card_class(%{cart_type: type}), do: "admin/#{String.downcase(type)}-cards"