So I use a headless cms for some static page content, but some of the pages should have dynamic embeds like a price table that is based on stripe products.
So my content arrives as markdown like so:
Lorem ipsum dolor sit, ...
<div data-include="price_table"></div>
I use Floki to replace data-includes with another template
Phoenix.Template.render_to_string(AlbumWeb.EmbedsHTML, include, "html",
test: 20
)
However my problem is that I would much rather use a controller here, where I can do some business logic (like fetch the products) before rendering the template. (I tried using apply/3 for a dynamic invocation but it doesn’t work)
Or would there be an even better way like using smart page layouts?
To elaborate a bit further:
embed = apply(AlbumWeb.EmbedsController, String.to_existing_atom(include), [conn, %{}])
This somehow modifies the connection so that I lose the Lorem ipsum and I only receive the price_table markup