All Projects → danhper → phoenix-active-link

danhper / phoenix-active-link

Licence: MIT license
Elixir/Phoenix view helper to manage "active" state of a link

Programming Languages

elixir
2628 projects

phoenix-active-link

Build Status

Elixir/Phoenix helper to create links with "active" state.

Installation

Add phoenix_active_link to your list of dependencies in mix.exs:

def deps do
  [{:phoenix_active_link, "~> 0.2.1"}]
end

Usage

First, add

import PhoenixActiveLink

to the quote of the view function in your web.ex.

You can then use the functions as follow:

<header>
  <ul>
    <%= active_link(@conn, "Dashboard", to: "/", active: [{Dashboard, :index}], wrap_tag: :li) %>
    <%= active_link(@conn, "Users", to: "/users", wrap_tag: :li) %>
    <%= active_link(@conn, to: "/users", wrap_tag: :li) do %>
      <img src="foo.png">
    <% end %>
  </ul>
</header>

If you prefer to write PhoenixActiveLink.active_link explicitly, you can skip the first step.

Example of Active Tags

To specify the active and inactive tags for the wrap tag, use class_active and class_inactive. Example:

<%= active_link(@conn, "Home", to: "/", wrap_tag: :li, class_active: "active nav-item", class_inactive: "nav-item") %>

Defaults can be set in the config.ex as noted in the documentation

Documentation

For more information, take a look at the documentation

Credits

This library is inspired by/ported from active_link_to.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].