-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Guides: request lifecycle and custom error pages #5068
Conversation
Our messenger appears as `@messenger`. | ||
|
||
The values we passed to the view from the controller are collectively called our "assigns". We could access our messenger value via `assigns.messenger` but through some metaprogramming, Phoenix gives us the much cleaner `@` syntax for use in templates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"We call "assigns" the values passed from the controller to views" read a bit backwards.
Remember our templates are written in HEEx (HTML+EEx). HEEx is a superset of EEx which is why it shares the `<%= %>` syntax. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New users might get tripped up by "EEx tags" vs "aren't we writing HEEx?" so this tries to head that off at the pass.
guides/request_lifecycle.md
Outdated
Here we are telling `Phoenix.Component` to embed all `.heex` templates found in the sibling `hello` directory into our module as function definitions. | ||
|
||
Next, we need to add files to the `lib/hello_web/controllers/hello_html` directory. | ||
|
||
Note the controller name (`HelloController`), the view name (`HelloHTML`), and the template directory (`hello`) all follow the same naming convention and are named after each other. They are also collocated together in the directory tree: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just white space so the important "next we" doesn't get lost.
@@ -117,7 +117,11 @@ defmodule HelloWeb.HelloHTML do | |||
end | |||
``` | |||
|
|||
Now in order to add templates to this view, we can either define them as function components directly in the module: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "either ..." was missing its friend, so i colocated both parts, functions and files then expand on them.
guides/request_lifecycle.md
Outdated
Now in order to add templates to this view, we can either define them as function components directly in the module: | ||
To add templates to this view, we can define them as function components in the module or in separate files. Function components are great for smaller templates and separate files are a good choice when you have a lot of markup or your functions start to feel unmanageable. | ||
|
||
Both functional components and template files are compiled to an internal format, there is no runtime or performance difference between them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure this is true^1 and should ease some new users questions ("are files slower? does it read each time?")
- at least in prod, which I debated noting down but thought it was a bit much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of this line we could say:
Template files are compiled into the module, so there is no runtime or performance difference between using a separate file or the
~H
sigil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using the term "~H sigil" might be premature as we've not discussed ~H
or sigils yet (it is in the next post-code para though). The reader might go "what is a function component? wait what is ~H?" vs reusing the same terms we just outlaid.
How do you feel about this?
To add templates to this view, we can define them as function components in the module or in separate files. Function components are great for smaller templates and separate files are a good choice when you have a lot of markup or your functions start to feel unmanageable.
Template files are compiled into the module as function components themselves, there is no runtime or performance difference between the two styles.
The only real key point I think we need to make is that the reader shouldn't stress about picking between the two!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
@@ -27,7 +27,7 @@ defmodule HelloWeb.ErrorHTML do | |||
end | |||
end | |||
|
|||
defmodule HelloWeb.ErrorJSOn do | |||
defmodule HelloWeb.ErrorJSON do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops
|
||
They are rendered in the error page as a collection of buttons and follow the format of: | ||
When `debug_errors` is `true`, they are rendered in the error page as a collection of buttons and follow the format of: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user may have turned this off previously in the guide, so important to note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good changes. I've made one small suggestion that clarifies slightly what happens with template files.
guides/request_lifecycle.md
Outdated
Now in order to add templates to this view, we can either define them as function components directly in the module: | ||
To add templates to this view, we can define them as function components in the module or in separate files. Function components are great for smaller templates and separate files are a good choice when you have a lot of markup or your functions start to feel unmanageable. | ||
|
||
Both functional components and template files are compiled to an internal format, there is no runtime or performance difference between them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of this line we could say:
Template files are compiled into the module, so there is no runtime or performance difference between using a separate file or the
~H
sigil.
5f65f09
to
6c449e7
Compare
Fixed merge conflict & applied feedback |
Thanks <3 |
No description provided.