Browse Source

Parametrize hello page

master
Piotr Orzechowski 1 month ago
parent
commit
3ab05ddd30
3 changed files with 4 additions and 4 deletions
  1. +2
    -2
      hello/lib/hello_web/controllers/hello_controller.ex
  2. +1
    -1
      hello/lib/hello_web/router.ex
  3. +1
    -1
      hello/lib/hello_web/templates/hello/world.html.eex

+ 2
- 2
hello/lib/hello_web/controllers/hello_controller.ex View File

@@ -1,7 +1,7 @@
defmodule HelloWeb.HelloController do
use HelloWeb, :controller

def world(conn, _params) do
render(conn, "world.html")
def world(conn, %{"name" => name}) do
render(conn, "world.html", name: name)
end
end

+ 1
- 1
hello/lib/hello_web/router.ex View File

@@ -16,7 +16,7 @@ defmodule HelloWeb.Router do
scope "/", HelloWeb do
pipe_through :browser

get "/hello", HelloController, :world
get "/hello/:name", HelloController, :world
get "/", PageController, :index
end


+ 1
- 1
hello/lib/hello_web/templates/hello/world.html.eex View File

@@ -1 +1 @@
<h1>From template: Hello world!</h1>
<h1>From template: Hello <%= String.capitalize(@name) %>!</h1>

Loading…
Cancel
Save