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

Guides: request lifecycle and custom error pages #5068

Merged
merged 7 commits into from
Nov 9, 2022

Conversation

rktjmp
Copy link
Contributor

@rktjmp rktjmp commented Nov 3, 2022

No description provided.

Comment on lines +286 to +288
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.
Copy link
Contributor Author

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.

Comment on lines +276 to +277
Remember our templates are written in HEEx (HTML+EEx). HEEx is a superset of EEx which is why it shares the `<%= %>` syntax.

Copy link
Contributor Author

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.

Comment on lines 150 to 154
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:
Copy link
Contributor Author

@rktjmp rktjmp Nov 3, 2022

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:
Copy link
Contributor Author

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.

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.
Copy link
Contributor Author

@rktjmp rktjmp Nov 3, 2022

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

  1. at least in prod, which I debated noting down but thought it was a bit much.

Copy link
Member

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.

Copy link
Contributor Author

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!

Copy link
Member

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
Copy link
Contributor Author

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:
Copy link
Contributor Author

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.

@rktjmp rktjmp marked this pull request as ready for review November 3, 2022 09:33
Copy link
Member

@Gazler Gazler left a 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.

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.
Copy link
Member

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.

@rktjmp
Copy link
Contributor Author

rktjmp commented Nov 9, 2022

Fixed merge conflict & applied feedback

@Gazler Gazler merged commit fc6a55b into phoenixframework:master Nov 9, 2022
@Gazler
Copy link
Member

Gazler commented Nov 9, 2022

Thanks <3

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

Successfully merging this pull request may close these issues.

3 participants