In my LiveView app, I use live_title_tag
to generate a dynamic browser title. Works great!
I’d also like to have a dynamic favicon but haven’t been able to get that working.
In my helper module MyWeb.LiveHelpers
I put a function component:
def favicon_tag(assigns) do
color = assigns[:color] || "black"
href="/img/favicon-#{color}.ico"
~H"""
<link rel="icon" type="image/x-icon" href={href} size="32x32"/>
"""
end
In my layout/root_live.html.heex
I add the tag:
<MyWeb.LiveHelpers.favicon_tag color={assigns[:color]} />
The function component is called once when the page first loads, but is not re-run when I change the value of the color attribute.
Should this work? Can I update the favicon dynamically with LiveView, or do I have to fall back to Javascript?