Recommended way to pass multiple (a lot) of parameters to the view

Hi guys,

I’d generated the descriptive statistics of certain data, the problem I’m facing right now is how to pass a lot of these small values to my view while keeping my code clean

Example of what I have right now:

render(
  conn,
  "index.html",
  np: np,
  cd: cd,
  r1: r1,
  r2: r2,
  r3: r3,
  r4: r4,
  ...,
)

What do you think?

You can define a map before the render:

data = %{
  np: np,
  cd: cd,
  r1: r1,
  r2: r2,
  r3: r3,
  r4: r4,
  ...
}

render(conn, "index.html", data)
1 Like

Yes, but I want to keep the controller cleaner, what about create a function onto the model that returns that map? the model should not take care of that?

Why not creating another module for that? If this is an explicit use case and may contain a long struct (I’m assuming that for some keys you gonna have special treatment). export that logic inside it’s on module makes a lot of sense.

3 Likes

Great idea, ty!