O'Reilly logo

Programming Phoenix by Jose Valim, Bruce Tate, Chris McCord

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Helpers

That link function packs a surprising amount of punch into a small package. Phoenix helpers provide a convenient way to drop common HTML structures onto your view. There’s nothing special about them. Helpers are simply Elixir functions. For example, you can call the functions directly in IEx:

 $ ​​iex​​ ​​-S​​ ​​mix
 iex>​ Phoenix.HTML.Link.link(​"​​Home"​, ​to:​ ​"​​/"​)
 {:safe, ["<a href=\"/\">", "Home", "</a>"]}
 
 iex>​ Phoenix.HTML.Link.link(​"​​Delete"​, ​to:​ ​"​​/"​, ​method:​ ​"​​delete"​)
 {:safe,
  [["<form action=\"/\" class=\"link\" method=\"post\">",
  "<input name=\"_method\" type=\"hidden\" value=\"delete\">
  <input name=\"_csrf_token\" type=\"hidden\" value=\"UhdjBFUcOh...\">"],
  ["<a data-submit=\"parent\" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required