i’m developing a basic phoenix component (not liveview). in this component i’m trying to assign a new value to the assigns coming in, and then use that value. this is what i have
defmodule Web.Components.MyComponent do
use Phoenix.Component
embed_templates("../../templates/my_template")
def action(assigns) do
assigns = assign(assigns, :result, 100)
~H"""
<._my_template assigns={assigns}/>
"""
end
end
Inside _my_template
i have the following
This is the result <%= @result %>
However when the code runs i see the following error
# key :result not found in: %{__changed__: nil, assigns: %{__changed__: nil, id: "my_comp1", result: 100}}
looks like the code added the assigns into another assigns. not sure what to do about this.
furthermore i discovered that its with embed_templates that i’m having this issue. if i simply inline the content in my_template
then it seems to work fine.