Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mismatch template #197

Open
tduccuong opened this issue Feb 18, 2020 · 7 comments
Open

mismatch template #197

tduccuong opened this issue Feb 18, 2020 · 7 comments

Comments

@tduccuong
Copy link

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?

@OvermindDL1
Copy link
Collaborator

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? :-)

@tduccuong
Copy link
Author

it is already app.html.drab :-) let me try to create a minimize project...

@OvermindDL1
Copy link
Collaborator

Yeah I'm quite curious now. ^.^

Thanks!

@tduccuong
Copy link
Author

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?

@OvermindDL1
Copy link
Collaborator

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!

@tduccuong
Copy link
Author

so, here is the mini project: drab_test
There are two issues with it:

  • login handler only works if main layout is app.html.eex, fails when rename the layout to app.html.drab
  • CSS is messed up when layout has .eex extension. When changing it back to app.html.drab, CSS looks nice again!

Thanks a lot 👍

@OvermindDL1
Copy link
Collaborator

Awesome! I'll look at it when I can, thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants