shahryarjb
Call a LiveView/Phoenix component dynamically
Imagine you have a core component for LiveView/Phoenix component, and it has some static component like icon
For example:
<Heroicons.inbox_stack class="w-6 h-6 mx-auto stroke-current" />
You want to load it in a loop something like this:
<.block :for={{id, title, icon_module} <- tailwind_settings} id={id} title={title}>
<icon_module class="w-6 h-6 mx-auto stroke-current" />
</.block>
How can we implement it?
Thank you in advance.
First Post!
shahryarjb
I found Phoenix.LiveView.HTMLEngine.component, but I could not use with string name of Elixir module and function like: "Elixir.Heroicons.inbox_stack"
<.block :for={{id, title, module} <- tailwind_settings} id={id} title={title}>
<%= Phoenix.LiveView.HTMLEngine.component(
String.to_existing_atom(module),
[class: "w-6 h-6 mx-auto stroke-current"],
{__ENV__.module, __ENV__.function, __ENV__.file, __ENV__.line}
) %>
</.block>
This function needs 3 arity and I can’t use apply, so String.to_existing_atom(module) is just used for converting to module
Do you have any idea?
Thanks
Most Liked
mplatts
LostKobrakai
Seems it got moved to Phoenix.LiveView.TagEngine: Open Tokenizer for customization by feliperenan · Pull Request #2482 · phoenixframework/phoenix_live_view · GitHub
LostKobrakai
Last Post!
mustela
You rock @LostKobrakai ! Thanks a lot! I need to find a “public” api to do this before it changes again.
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
- #code-sync
- #javascript
- #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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









