I have a Phoenix app in which I need to display User's profiles in EEx / HTML, but each User's profile has varying fields, including nested data.
This would be simple to do if every user's profile had the same fields, as I could just print them straight into the EEx, but as every user has a different profile, I can't match fields.
I'm looking for the best way to loop over the User
data, including the nested attributes and display the Keys/Values in EEx, line by line.
The User data looks like this:
[closed: :null, created: "2015-10-10T00:51:11.611Z",
email: "email@gmail.com",
id: "user-1234", name: "Rbin",
profile: %{"something" => 2,
"laptop" => %{"age" => 2, "price" => "High", "size" => "13",
"type" => "Macbook", "working" => true}, "silly" => "properties"},
sessions: %{"type" => "list",
"url" => "/user-1234/sessions"}, type: "user",
url: "/users/user-1234", username: "rbin"]
Listing multiple users was easy, as I could do a list comprehension and use a for users <- users do
. I'm pretty sure I can't use that in this scenario though.