@view_template meaning changed in phoenix 1.5

the @view_template variable as accessed in the app.html layout of a 1.4 phoenix app contained the name of the template being rendered by the controller

in phoenix 1.5 I get root.html, the name of the new template, first in the chain, under a live setup

how to recover the name of the template being rendered (information needed in the root.html layout )?

1 Like

according to the docs https://hexdocs.pm/phoenix/Phoenix.View.html

The following assigns are reserved, and cannot be set directly:

  • @view_module - The view module being rendered
  • @view_template - The @view_module 's template being rendered

but when I serve a template mytemp.html from a controller Mycont @view_template does not contain mytemp but only root.html @view_modules contain LayoutView

previously in 1.4.6 we had @view_template mytemp.html and view_module MycontView

so how od you get the name of the template being rendered in @inner_view ? which should be mytemp.html ?

2 Likes

the old behaviour is recovered if one avoids using in router.ex


    plug :put_root_layout, {AppWeb.LayoutView, :root}

You could use the trick described in a comment about the phx-1.5-upgrade.md upgrade guide which gets :phoenix_template and :phoenix_view from conn.private.

For the @view_module and @view_template, use view_module(@conn) and view_template(@conn) instead. Note you will need to import view_template: 1 in your my_app_web.ex file under def view.

4 Likes

Btw, it is not that the meaning changed, they are the same for app.html.eex, but root.html.eex has a different interpretation of those.

1 Like

Thanks, that makes the proposed temporary trick useless. Everything is back to a clean state.

Thank you it works