mendrik

mendrik

Embedding controllers into controllers

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

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54092 488
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New

We're in Beta

About us Mission Statement