mismatch template
tduccuong opened this issue · comments
I have a login_controller
that renders index.html.drab
in templates/login/
with this content:
<%= if @error !== nil do %>
<p>
<%= @error %>
</p>
<% end %>
<button drab-click="login" type="button">Login</button>
I also defined the corresponding login_commander
with simply:
defhandler login(socket, _sender) do
poke socket, error: "Test error!"
end
When clicking the button, i got this error
[error] Drab Handler failed with the following exception:
** (Phoenix.Template.UndefinedError) Could not render "lib/tgshop_web/templates/layout/app.html" for TgshopWeb.LoginView, please define a matching clause for render/2 or define a template at "lib/tgshop_web/templates/login/*". The following templates were compiled:
* index.html
Assigns:
%{conn: %Plug.Conn{adapter: {Plug.MissingAdapter, :...}, assigns: %{}, before_send: [], body_params: %Plug.Conn.Unfetched{aspect: :body_params}, cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false, host: "www.example.com", method: "GET", owner: nil, params: %Plug.Conn.Unfetched{aspect: :params}, path_info: [], path_params: %{}, port: 0, private: %{phoenix_action: :index, phoenix_controller: TgshopWeb.LoginController, phoenix_endpoint: TgshopWeb.Endpoint}, query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_string: "", remote_ip: nil, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies}, req_headers: [], request_path: "", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}], scheme: :http, script_name: [], secret_key_base: nil, state: :unset, status: nil}, error: "Test error!", view_module: TgshopWeb.LoginView, view_template: "lib/tgshop_web/templates/layout/app.html"}
Assigned keys: [:conn, :error, :view_module, :view_template]
(phoenix 1.4.13) lib/phoenix/template.ex:341: Phoenix.Template.raise_template_not_found/3
(phoenix 1.4.13) lib/phoenix/view.ex:410: Phoenix.View.render_to_iodata/3
(phoenix 1.4.13) lib/phoenix/view.ex:417: Phoenix.View.render_to_string/3
(drab 0.10.3) lib/drab/live.ex:692: Drab.Live.rerender_template/4
(drab 0.10.3) lib/drab/live.ex:647: Drab.Live.process_poke/9
(drab 0.10.3) lib/drab.ex:360: anonymous fn/7 in Drab.handle_event/6
What did I do wrong? Do I have to use mix drab.gen.commander Login
instead of creating the files by hand?
Hmm, I'm still learning the internals of Drab's Live processing, so can you try a test for me, try changing your layout's app.html.eex
to be app.html.drab
and recompile all and see if that works then and tell me the result? If that doesn't work would you be able to replicate it in a new minimized project and give me a git link for it here? :-)
it is already app.html.drab
:-) let me try to create a minimize project...
Yeah I'm quite curious now. ^.^
Thanks!
whatt? ok, it is weird that it works now when I changed app.html.drab
to app.html.eex
. So I guess you dont need the mini project after all?
Hmm, not weird, that actually might tell me what's going on. Go ahead and leave this open because that should still work regardless. If you want to make a minimized project I'd be very grateful though!
so, here is the mini project: drab_test
There are two issues with it:
login
handler only works if main layout isapp.html.eex
, fails when rename the layout toapp.html.drab
- CSS is messed up when layout has
.eex
extension. When changing it back toapp.html.drab
, CSS looks nice again!
Thanks a lot 👍
Awesome! I'll look at it when I can, thanks so much!