Skip to content

Commit 87159b5

Browse files
authored
Update Migrating to Phoenix.Component guide for LayoutView, ErrorView (#27)
* Update component migration guide, fix MyApp -> MyAppWeb * Update component migration guide, add LayoutView step * Update component migration guide, add ErrorView step
1 parent 01df488 commit 87159b5

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/phoenix_view.ex

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ defmodule Phoenix.View do
149149
1. Replace `render_existing/3` calls by `function_exported?/3` checks,
150150
according to the `render_existing` documentation.
151151
152-
2. Replace `use MyApp, :view` by `use MyApp, :html` and invoke
152+
2. Replace `use MyAppWeb, :view` by `use MyAppWeb, :html` and invoke
153153
`embed_templates "../templates/my/*"`. Alternatively, you can move
154154
both the HTML file and its templates to the `controllers` directory,
155155
to align with Phoenix v1.7 conventions.
@@ -165,6 +165,22 @@ defmodule Phoenix.View do
165165
You can address this by converting the layout into a function component
166166
that receives its contents as a slot. See `render_layout/4` docs
167167
168+
5. If you want to rename your `MyAppWeb.LayoutView` to `MyAppWeb.Layouts`
169+
you will need to update the `controller` function in `MyAppWeb`, giving
170+
the `use Phoenix.Controller` call a `layouts` option like so:
171+
172+
```
173+
use Phoenix.Controller,
174+
layouts: [html: MyAppWeb.Layouts]
175+
```
176+
177+
6. When updating your `ErrorView`, you will also need to rename `template_not_found/2`
178+
to `render/2`. You might have generated tests that will need to be
179+
updated as well. You can replace `import Phoenix.View` with `import Phoenix.Template`,
180+
and replace `Phoenix.View.render_to_string/3` calls with `Phoenix.Template.render_to_string/4`.
181+
Lastly, if you want to rename this to `ErrorHTML`, you will need to
182+
update the reference to `ErrorView` in your config for `MyAppWeb.Endpoint`.
183+
168184
Now you are using components! Once you convert all views, you should
169185
be able to remove `Phoenix.View` as a dependency from your project.
170186

0 commit comments

Comments
 (0)