Can I / How can I use common static heex templates in a Live View

Scenario:

I have a site with mixed static and Live View content.

For the static content, I have common page elements in /components/common

But for the life of me I can’t figure out how to embed these heex templates for use in a live view template.

I am sure this is a dead simple and common use case, but google is sending me down weird rabbit holes, and chat gpt wants me to make function-components that wrap the templates content.

Is that really the only answer?

Does calling them like this work:

<MyAppWeb.Components.Common.my_component />

?

If so, just make sure you import them into your def html_helpers in lib/my_app_web.ex (assuming you have a standard Phoenix project layout).

No, that doesn’t work.

Because I don’t have a module file for these templates, in the static part of the site, I am just using embed_templates "../components/common/*" it doesn’t look like there is a module I can import, and nor do the live view templates resolve that path.

It sounds like you are agreeing with ChatGPT that I need a module and functions for these templates rather than the embed_templates shortcut.

Oh ya, I never do that myself, but I think you can access them via the HTML module? I think you can define a bodyless function to use as components. Sorry I do not know off the top of my head.

Where‘s the embed_templates call? That‘s the module you want.

Templates on phoenix/elixir are just means of generating functions on a module from a separate file. At runtime it‘s all just modules and functions.

For my existing use case, the right answer was to expand the role of the layout, which has access to all the necessary scaffolding to access the components.

For a more general solution, I will return to this only if I need to.