diff --git a/.github/single-file-samples/main.exs b/.github/single-file-samples/main.exs index 88b63afcee..7f2171bfd1 100644 --- a/.github/single-file-samples/main.exs +++ b/.github/single-file-samples/main.exs @@ -43,13 +43,13 @@ defmodule Example.HomeLive do - <%= @inner_content %> + {@inner_content} """ end def render(assigns) do ~H""" - <%= @count %> + {@count} """ diff --git a/.github/single-file-samples/test.exs b/.github/single-file-samples/test.exs index d494dbd173..b78bb6a8d6 100644 --- a/.github/single-file-samples/test.exs +++ b/.github/single-file-samples/test.exs @@ -39,7 +39,7 @@ defmodule Example.HomeLive do - <%= @inner_content %> + {@inner_content} """ end diff --git a/guides/client/bindings.md b/guides/client/bindings.md index b2987b2ffe..951a947348 100644 --- a/guides/client/bindings.md +++ b/guides/client/bindings.md @@ -148,7 +148,7 @@ for example: def render(assigns) do ~H"""
- Current temperature: <%= @temperature %> + Current temperature: {@temperature}
""" end @@ -384,7 +384,7 @@ For example: ```heex

- <%= Phoenix.Flash.get(@flash, :info) %> + {Phoenix.Flash.get(@flash, :info)}

``` diff --git a/guides/client/js-interop.md b/guides/client/js-interop.md index 15d416819c..801dcf8eb9 100644 --- a/guides/client/js-interop.md +++ b/guides/client/js-interop.md @@ -78,7 +78,7 @@ element from the server to draw the user's attention: ```heex
- <%= item.title %> + {item.title}
``` @@ -110,7 +110,7 @@ attribute: ```heex
- <%= item.title %> + {item.title}
``` diff --git a/guides/introduction/welcome.md b/guides/introduction/welcome.md index d5e0e511a9..0ad98cb7e5 100644 --- a/guides/introduction/welcome.md +++ b/guides/introduction/welcome.md @@ -47,7 +47,7 @@ defmodule MyAppWeb.ThermostatLive do def render(assigns) do ~H""" - Current temperature: <%= @temperature %>°F + Current temperature: {@temperature}°F """ end @@ -235,7 +235,7 @@ function that receives an assigns map and returns a `~H` template. For example: def weather_greeting(assigns) do ~H"""
-

Hello <%= @name %>

+

Hello {@name}

""" diff --git a/guides/server/assigns-eex.md b/guides/server/assigns-eex.md index 62e37605cc..10958800f2 100644 --- a/guides/server/assigns-eex.md +++ b/guides/server/assigns-eex.md @@ -1,11 +1,11 @@ # Assigns and HEEx templates -All of the data in a LiveView is stored in the socket, which is a server +All of the data in a LiveView is stored in the socket, which is a server side struct called `Phoenix.LiveView.Socket`. Your own data is stored under the `assigns` key of said struct. The server data is never shared with the client beyond what your template renders. -Phoenix template language is called HEEx (HTML+EEx). EEx is Embedded +Phoenix template language is called HEEx (HTML+EEx). EEx is Embedded Elixir, an Elixir string template engine. Those templates are either files with the `.heex` extension or they are created directly in source files via the `~H` sigil. You can learn more about @@ -27,7 +27,7 @@ static and dynamic parts of the template to the client. Imagine the following template: ```heex -

<%= expand_title(@title) %>

+

{expand_title(@title)}

``` It has two static parts, `

` and `

` and one dynamic part @@ -46,7 +46,7 @@ Take this template: ```heex
- <%= @user.name %> + {@user.name}
``` @@ -58,7 +58,7 @@ The change tracking also works when rendering other templates as long as they are also `.heex` templates: ```heex -<%= render "child_template.html", assigns %> +{render("child_template.html", assigns)} ``` Or when using function components: @@ -73,7 +73,7 @@ query in your template: ```heex <%= for user <- Repo.all(User) do %> - <%= user.name %> + {user.name} <% end %> ``` @@ -102,13 +102,13 @@ this in your HEEx templates: ```heex <% some_var = @x + @y %> -<%= some_var %> +{some_var} ``` Instead, use a function: ```heex -<%= sum(@x, @y) %> +{sum(@x, @y)} ``` Similarly, **do not** define variables at the top of your `render` function @@ -120,9 +120,9 @@ if either value changes, both must be re-rendered by LiveView. title = assigns.title ~H""" -

<%= title %>

+

{title}

- <%= sum %> + {sum} """ end @@ -141,9 +141,9 @@ The same functions can be used inside function components too: assigns = assign(assigns, sum: assigns.x + assigns.y) ~H""" -

<%= @title %>

+

{@title}

- <%= @sum %> + {@sum} """ end @@ -168,7 +168,7 @@ and instead use `@` for accessing specific keys. This also applies to function components. Let's see some examples. Sometimes you might want to pass all assigns from one function component to -another. For example, imagine you have a complex `card` component with +another. For example, imagine you have a complex `card` component with header, content and footer section. You might refactor your component into three smaller components internally: @@ -209,7 +209,7 @@ def card(assigns) do
<.card_header title={@title} class={@title_class} /> <.card_body> - <%= render_slot(@inner_block) %> + {render_slot(@inner_block)} <.card_footer on_close={@on_close} />
@@ -225,9 +225,9 @@ templates is acceptable: def card(assigns) do ~H"""
- <%= card_header(assigns) %> - <%= card_body(assigns) %> - <%= card_footer(assigns) %> + {card_header(assigns)} + {card_body(assigns)} + {card_footer(assigns)}
""" end diff --git a/guides/server/live-layouts.md b/guides/server/live-layouts.md index 2a286a1173..c29ac1816d 100644 --- a/guides/server/live-layouts.md +++ b/guides/server/live-layouts.md @@ -17,7 +17,7 @@ From Phoenix v1.7, your application is made of two layouts: Overall, those layouts are found in `components/layouts` and are embedded within `MyAppWeb.Layouts`. -All layouts must call `<%= @inner_content %>` to inject the +All layouts must call `{@inner_content}` to inject the content rendered by the layout. ## Root layout @@ -71,7 +71,7 @@ mount: Then access `@page_title` in the root layout: ```heex -<%= @page_title %> +{@page_title} ``` You can also use the `Phoenix.Component.live_title/1` component to support @@ -79,8 +79,8 @@ adding automatic prefix and suffix to the page title when rendered and on subsequent updates: ```heex - - <%= assigns[:page_title] || "Welcome" %> + + {assigns[:page_title]} ``` diff --git a/guides/server/uploads.md b/guides/server/uploads.md index a5424452b5..9d630ae1fa 100644 --- a/guides/server/uploads.md +++ b/guides/server/uploads.md @@ -82,35 +82,27 @@ Let's look at an annotated example: <%!-- use phx-drop-target with the upload ref to enable file drag and drop --%>
- -<%!-- render each avatar entry --%> -<%= for entry <- @uploads.avatar.entries do %> -
- + <%!-- render each avatar entry --%> +
<.live_img_preview entry={entry} /> -
<%= entry.client_name %>
+
{entry.client_name}
<%!-- entry.progress will update automatically for in-flight entries --%> - <%= entry.progress %>% + {entry.progress}% <%!-- a regular click event whose handler will invoke Phoenix.LiveView.cancel_upload/3 --%> <%!-- Phoenix.Component.upload_errors/2 returns a list of error atoms --%> - <%= for err <- upload_errors(@uploads.avatar, entry) do %> -

<%= error_to_string(err) %>

- <% end %> - +

{error_to_string(err)}

-<% end %> - -<%!-- Phoenix.Component.upload_errors/1 returns a list of error atoms --%> -<%= for err <- upload_errors(@uploads.avatar) do %> -

<%= error_to_string(err) %>

-<% end %> + <%!-- Phoenix.Component.upload_errors/1 returns a list of error atoms --%> +

+ {error_to_string(err)} +

``` diff --git a/lib/phoenix_component.ex b/lib/phoenix_component.ex index 8253932572..e6594f7d56 100644 --- a/lib/phoenix_component.ex +++ b/lib/phoenix_component.ex @@ -12,7 +12,7 @@ defmodule Phoenix.Component do def greet(assigns) do ~H""" -

Hello, <%= @name %>!

+

Hello, {@name}!

""" end end @@ -20,8 +20,9 @@ defmodule Phoenix.Component do This function uses the `~H` sigil to return a rendered template. `~H` stands for HEEx (HTML + EEx). HEEx is a template language for writing HTML mixed with Elixir interpolation. We can write Elixir - code inside HEEx using `<%= ... %>` tags and we use `@name` to - access the key `name` defined inside `assigns`. + code inside `{...}` for HTML-aware interpolation inside tag attributes + and the body. We can also interpolate arbitrary HEEx blocks using `<%= ... %>` + We use `@name` to access the key `name` defined inside `assigns`. When invoked within a `~H` sigil or HEEx template file: @@ -68,7 +69,7 @@ defmodule Phoenix.Component do def greet(assigns) do ~H""" -

Hello, <%= @name %>!

+

Hello, {@name}!

""" end @@ -110,8 +111,8 @@ defmodule Phoenix.Component do def celebrate(assigns) do ~H"""

- Happy birthday <%= @name %>! - You are <%= @age %> years old. + Happy birthday {@name}! + You are {@age} years old.

""" end @@ -143,7 +144,7 @@ defmodule Phoenix.Component do def heading(assigns) do ~H""" -

<%= @title %>

+

{@title}

""" end @@ -151,7 +152,7 @@ defmodule Phoenix.Component do def greet(assigns) do ~H""" -

Hello <%= @name %>

+

Hello {@name}

""" end end @@ -178,7 +179,7 @@ defmodule Phoenix.Component do def notification(assigns) do ~H""" - <%= @message %> + {@message} """ end @@ -233,7 +234,7 @@ defmodule Phoenix.Component do slot :inner_block def button(assigns) do ~H""" - + """ end ``` @@ -281,7 +282,7 @@ defmodule Phoenix.Component do def button(assigns) do ~H""" """ end @@ -327,10 +328,8 @@ defmodule Phoenix.Component do def unordered_list(assigns) do ~H""" -