By not trying to implement the algorythm in the template.
<%= for {period, index} <- Enum.with_index(combine_by_type(@school_vacation_periods)) do %>
…
<% end %>
… where combine_by_type
uses some of the approaches of the other topic you opened.