# Passing second parameter to render function in phoenix

**URL:** <https://forum.elixirforum.com/t/passing-second-parameter-to-render-function-in-phoenix/8752>\
**Category:** Questions\
**Tags:** ecto, phoenix\
**Created:** [September 19, 2017, 4:34pm UTC](https://forum.elixirforum.com/t/passing-second-parameter-to-render-function-in-phoenix/8752 "2017-09-19T16:34:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lastday4you](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lastday4you/32/10304_2.png) [@lastday4you](https://forum.elixirforum.com/u/lastday4you)\
**Post date:** [September 19, 2017, 4:34pm UTC](https://forum.elixirforum.com/t/passing-second-parameter-to-render-function-in-phoenix/8752/1 "2017-09-19T16:34:54Z")

</div>

```elixir
 def render("login.json", %{jwt: jwt, user: user}) do
    %{data: render_one(%{jwt: jwt, user: user}, Catastore.SessionView, "session.json")}
  end

  def render("session.json", %{jwt: jwt, user: user}) do
    IO.inspect jwt
    %{
      access_token: jwt,
      user: #user render many
    }
  end

```

but this give me error

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [September 19, 2017, 4:39pm UTC](https://forum.elixirforum.com/t/passing-second-parameter-to-render-function-in-phoenix/8752/2 "2017-09-19T16:39:55Z")

</div>

> [@lastday4you](#):
>
> but this give me error

Which one?

Only glancing, I’d guess that there will be a compile time warning about unused variable `user`, but can’t see and error (at least not compile time)…

---

<div class="post-metadata">

**Author:** ![lastday4you](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lastday4you/32/10304_2.png) [@lastday4you](https://forum.elixirforum.com/u/lastday4you)\
**Post date:** [September 19, 2017, 4:42pm UTC](https://forum.elixirforum.com/t/passing-second-parameter-to-render-function-in-phoenix/8752/3 "2017-09-19T16:42:15Z")

</div>

i am sorry was a bit sleepy i copy the code wrong updated the question now

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [September 19, 2017, 4:44pm UTC](https://forum.elixirforum.com/t/passing-second-parameter-to-render-function-in-phoenix/8752/4 "2017-09-19T16:44:55Z")

</div>

I’d prefered if you had answered just my question with updated code, now my last post is out of context…

Despite this, you didn’t tell us what error you get.

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/32/2677_2.png) [@OvermindDL1](https://forum.elixirforum.com/u/OvermindDL1)\
**Post date:** [September 19, 2017, 4:49pm UTC](https://forum.elixirforum.com/t/passing-second-parameter-to-render-function-in-phoenix/8752/5 "2017-09-19T16:49:43Z")

</div>

> [@lastday4you](#):
>
> but this give me error

I’m not seeing any error in your post?

However I’m guessing that the `render_one` call in your first render function is wrong, as I don’t think you have anything that accepts a map for the resource? ^.^;

---

<div class="post-metadata">

**Author:** ![lastday4you](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lastday4you/32/10304_2.png) [@lastday4you](https://forum.elixirforum.com/u/lastday4you)\
**Post date:** [September 19, 2017, 4:51pm UTC](https://forum.elixirforum.com/t/passing-second-parameter-to-render-function-in-phoenix/8752/6 "2017-09-19T16:51:07Z")

</div>

oh sorry, was so sleepy and doing thing too fast xD here the error code :

> Could not render “session.json” for Catastore.SessionView, please define a matching clause for render/2 or define a template at “web/templates/session”

here is my render code  
`render(conn, "login.json", %{jwt: jwt, user: user})`

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/32/2677_2.png) [@OvermindDL1](https://forum.elixirforum.com/u/OvermindDL1)\
**Post date:** [September 19, 2017, 4:53pm UTC](https://forum.elixirforum.com/t/passing-second-parameter-to-render-function-in-phoenix/8752/7 "2017-09-19T16:53:43Z")

</div>

> [@lastday4you](#):
>
> Could not render “session.json” for Catastore.SessionView, please define a matching clause for render/2 or define a template at “web/templates/session”

> [@lastday4you](#):
>
> %{data: render\_one(%{jwt: jwt, user: user}, Catastore.SessionView, “session.json”)}

You probably want this as:

```elixir
%{data: render(Catastore.SessionView, "session.json", %{jwt: jwt, user: user})}

```

---

<div class="post-metadata">

**Author:** ![lastday4you](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lastday4you/32/10304_2.png) [@lastday4you](https://forum.elixirforum.com/u/lastday4you)\
**Post date:** [September 19, 2017, 4:56pm UTC](https://forum.elixirforum.com/t/passing-second-parameter-to-render-function-in-phoenix/8752/8 "2017-09-19T16:56:13Z")

</div>

Thank you it work now but just out of curiosity why can i pass the map like that ?

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/32/2677_2.png) [@OvermindDL1](https://forum.elixirforum.com/u/OvermindDL1)\
**Post date:** [September 19, 2017, 5:01pm UTC](https://forum.elixirforum.com/t/passing-second-parameter-to-render-function-in-phoenix/8752/9 "2017-09-19T17:01:26Z")

</div>

> [@lastday4you](#):
>
> Thank you it work now but just out of curiosity why can i pass the map like that ?

Well in render\_one it is expecting a single element that it will then put in a names assign (defaults to something that I don’t remember, can rename it with `as: :blah`).

The `render` function takes the set of assigns as it’s last argument.

---

<div class="post-metadata">

**Author:** ![lastday4you](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lastday4you/32/10304_2.png) [@lastday4you](https://forum.elixirforum.com/u/lastday4you)\
**Post date:** [September 19, 2017, 5:15pm UTC](https://forum.elixirforum.com/t/passing-second-parameter-to-render-function-in-phoenix/8752/10 "2017-09-19T17:15:05Z")

</div>

i see, thank you very much i got it now
