Drab: assign not found in Drab EEx template

I know there are some similar questions but I couldn’t find the answer to my question though I think I’ve already seen it somewhere… Sorry in advance if this is duplicated.

I’ve this two templates:


<%= render __MODULE__, "_login_form.html", conn: @conn, loading: false %>


<%= if @loading do %>
  <%= gettext "Logging in..." %>
<% else %>
  <%= gettext "Login" %>
<% end %>

With the above setup, I get the following error:

[error] Drab Handler failed with the following exception:
** (ArgumentError) assign @loading not found in Drab EEx template.

Please make sure all proper assigns have been set. If this
is a child template, ensure assigns are given explicitly by
the parent template as they are not automatically forwarded.

Available assigns:

However if in the _login_form.html.drab template I add:

<%= @loading %>

It starts working… What’s the difference here between using like <%= @loading %> or <%= if @loading, do: "Loading" %> regarding Drab?


Just to be sure, do you use the template name in poke or peek?

poke socket, "_login_form.html", loading: false

And also, which version of Drab do you use?

I use in poke and have `{:drab, “~> 0.9”}.

But do you use poke with the partial name? (probably yes, but I want to be sure about it)

What I mean is, when you use the poke/2, without the partial name:

poke socket, loading: false

It will try to update the assign in the main partial, so in your case, “new.html”. And in this partial @loading does not exists, doesn’t it?

To update an assign in the child partial, you need to specify which, by using poke/3 or even poke/4:

poke socket, "_login_form.html", loading: false

I’m specifying the template name. Already found the “issue”. I was creating a new project to reproduce this issue I was having but, surprisingly (or not), it was working fine!

Solution: rm -rf _build deps and it’s working…

Sorry for the time @grych and thanks for the help!