Normally when we write a Liveview UI, we use ~H sigil or provide a .heex file.
What I want to do is that I want to load some external content served as Liveview UI.
Such as ~r, it can be called as:
iex(3)> a = "b"
"b"
iex(4)> sigil_r("#{a}", 'i')
~r/b/i
Can I call the ~H sigil as a normal function by providing it a variable which contains the content?
I cannot figure out yet.
You generally don’t want to compile templates at runtime. Compiling templates might be rather expensive. If you really need runtime templates I’d suggest benchmarking and possibly caching the compiled templates.
Is the external content trusted? Keep in mind that HEEx is elixir code. If the external source is untrusted, or can be compromised, someone can run arbitrary Elixir code inside your application. I would consider something like mustache templates for external resources.
Are you talking about the Phoenix.LiveView.Helpers.component/2 function or the macro helper render_component/2 that you mentioned in the thread I linked?
If it’s the first one, some clarification in the docs might be needed to make it a bit more explicit because (I for instance didn’t even remember this function existed ):
Renders a component defined by the given function.
This function is rarely invoked directly by users. Instead, it is used by ~H to render Phoenix.Components.