teatimes
Difference between <%= and <. is heex-files
What is the difference between using <%= and <. in heex-files? After what I have understood, the second one is new to .heex-files and liveview, and I see it is used e.g. for live_components. Is there any differences, or are they interchangeable?
Marked As Solved
lubien
<%= @something %> is used to render @something on your HTML as long as it can become a string. You could change something to 1 + 1 or inspect(@current_user) and it would render something. <% and <%= are called tags in the docs for heex. I like to call them interpolation.
As for <.something> it means there’s a function on this module or imported in this module that’s a Phoenix.Component
These functions would be defined as:
def something(assigns) do
~H"""
Some heex here
"""
end
They take an assigns argument and everything you pass as parameters go there. Like <.something x={10} /> populates the assigns with assigns.x with value 10. You can also use inside heex @x since it’s an assign.
Worth mentioning the “.” At the start means “it’s here or imported here”. If you wanted to call a Phoenix.Component function from another module you’d do: <Other.Module.function_name x={10} />. (Note there’s no leading dot).
Also Liked
teatimes
Thank you for the clarifications!
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








