Last active
January 12, 2017 22:46
-
-
Save magynhard/be61a8753362300c8634dda422d99609 to your computer and use it in GitHub Desktop.
Elixir Phoenix Framework: Add class to active navigation entry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<div class="container"> | |
<%= render "top_navi.html", conn: @conn %> | |
</div> | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.LayoutView do | |
use MyApp.Web, :view | |
import MyApp.PageHelper | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.PageHelper do | |
use MyApp.Web, :controller | |
def page_path?(conn, method) do | |
current_path = Path.join(["/" | conn.path_info]) | |
cond do | |
page_path(conn, method) == current_path -> true | |
true -> false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment