How to display a value in a template?

Hello! Sorry for the dumb question but how do I display a variable in template. Let’s say I have an input in template and a button for submitting it. Once submitting, the value that I entered in my input passes to a controller. I was able to get the value through the controller and my problem is how do I display it on the same template?

do you want to show the value in the template your controller action returns? if so then the you need to pass your value in teh render/3 function, for example:

Given a controller:

defmodule MyAppWeb.MyController do
  use MyAppWeb, :controller

  def new(conn, params = %{"value" => my_value}) do
   # do your stuff
   render(conn, "new.html", value: my_value)


render/3 accepts a keyword list or a map as last argument, so anything you need to send to template you put there with a key, so on you template you can access it as

<span><%= @value %></span>

btw, there is no such thing as dumb question! :smile:


I gott the error:

assign @value not available in eex template.

Do you mind sharing your controller and template code?


Most of the times, try restarting mix phx.server.