HTML helper functions to create Font Awesome tags easily in Phoenix. Based on the great font-awesome-rails gem, we just couldn't live without it in Phoenix.
Please note this does not include Font Awesome itself, just helpers to make it easier to use.
-
Add font_awesome_phoenix to your list of dependencies in
mix.exs
:def deps do [{:font_awesome_phoenix, "~> 1.0"}] end
-
Add the HTML module to your
web.ex
to make it available to your templates:def view do ... import FontAwesomePhoenix.HTML end
In your templates:
<%= fa_icon("globe") %>
# <i class="fa fa-globe"></i>
<%= fa_icon(["globe", "2x"]) %>
# <i class="fa fa-globe fa-2x"></i>
<%= fa_icon("home", text: "Back to Home!") %>
# <i class="fa fa-home"></i> Back to Home!
<%= fa_icon("user-plus", text: "New User", align_tag: :right) %>
# New User <i class="fa fa-user-plus"></i>
<%= fa_icon("camera-retro 4x", class: "myclass") %>
# <i class="fa fa-camera-retro fa-4x myclass"></i>
<%= fa_icon("at", class: "x", data: [mood: :happy]) do %>
<span class="foo">Something</span>
<% end %>
# <i class="fa fa-at x" data-mood="happy">
# <span class="foo">Something</span>
# </i>
Passed-in text and classes are escaped, and the returned strings are marked safe. Be sure to read the documentation too!