In the post/show template I have:
<%= for comment <- @comments do %>
if (condition) do
# pass comment to _scripts.html
end
end
The objective is that in the _scripts.html, I need the comment available. (_scripts.html has javascript associated with the template)
By default, if I don’t do anything then the render line in post controller render(conn, "show.html", post: post, comments: comments) gives _scripts.html the Available assigns: [:conn, :post, :comments, ...].
So therefore to inject comment into the available assigns I do:
if (condition) do
# pass comment to _scripts.html
<%= render "_scripts.html", Map.put(@conn.assigns, :comment, comment) %>
end
which gives available assigns: [:comment, :post, :comments, ...] but the conn goes missing.
So, instead I tried doing:
if (condition) do
# pass comment to _scripts.html
<%= render "_scripts.html", Map.merge(@conn.assigns, %{comment: comment, conn: @conn}) %>
end
but then conn is available while comment goes missing, as in: assign @comment not available in eex template. Available assigns: [:conn, :post, :comments, ...]
Any help on this will be appreciated.






















