# Embedding controllers into controllers

**URL:** <https://forum.elixirforum.com/t/embedding-controllers-into-controllers/63201>\
**Category:** Questions\
**Tags:** phoenix, templates\
**Created:** [April 29, 2024, 8:22am UTC](https://forum.elixirforum.com/t/embedding-controllers-into-controllers/63201 "2024-04-29T08:22:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mendrik](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mendrik/32/33900_2.png) [@mendrik](https://forum.elixirforum.com/u/mendrik)\
**Post date:** [April 29, 2024, 8:22am UTC](https://forum.elixirforum.com/t/embedding-controllers-into-controllers/63201/1 "2024-04-29T08:22:30Z")

</div>

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:

```elixir
Lorem ipsum dolor sit, ...
<div data-include="price_table"></div>

```

I use Floki to replace data-includes with another template

```elixir
 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:

```elixir
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
