I’ve been experimenting with converting a simple dashboard page to LiveView, and I’m getting a strange error that I can’t track down.
I have a sites.html.leex
template, rendered from my LiveView, containing the following:
<div>
<%= for site <- @sites do %>
<%= render "site.html", %{site: site} %>
<% end %>
</div>
This works fine when the page initially loads, but when an event triggers my LiveView’s handle_info
to assign a new sites
list, the LiveView crashes, with the following error:
[error] GenServer #PID<0.1544.0> terminating
** (MatchError) no match of right hand side value: :comprehension
(premonition) lib/premonition_web/templates/dashboard/site.html.leex:1: PremonitionWeb.DashboardView."site.html"/1
(premonition) lib/premonition_web/templates/dashboard/sites.html.leex:3: anonymous fn/2 in PremonitionWeb.DashboardView."sites.html"/1
If I take the contents of the child template (site.html.leex
) and paste it inside the list comprehension instead, it works, but I’d prefer not to keep everything in one big template if possible. I initially thought it might not be possible, so I tried modifying the “CRUD Users” sample app from the LiveView project to render a partial template using virtually identical code, and I don’t get the error.
I realise this is pretty much impossible to diagnose from just that description (unless someone’s seem it before and knows what obvious mistake I’ve made), but can anyone suggest where I should be looking to get to the bottom of it?
Many thanks!