I have an template that is creating tags that are links.
I would like to add commas between the tags.
How can I do this so that the last tag does not have a comma.
<%= for tag <- @video.tags do %>
<%= link tag.name , to: tag_path(@conn, :show, tag.name) %>,
<% end %>
# in the view module
def format_tags(conn, tags) do
tags
|> Enum.map(fn tag -> link(tag.name, to: tag_path(conn, :show, tag.name) end)
|> Enum.intersperse(", ")
end
# in the template
<%= format_tags(@conn, @video.tags) %>
I’m starting to understanding how you can use the view module now.
You can create your list of html tags inside it and then use it in the template. Makes sense.
I always wanted to know what “Enum.intersperse” did. Cool example.