Last active
August 14, 2017 18:53
-
-
Save markbates/23acca9a43d16fe2e96cb6b4f834d0fb to your computer and use it in GitHub Desktop.
This file contains 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
// option 1: | |
// actions/render.go | |
"isCurrentPathName": func(name string, help plush.HelperContext) bool { | |
if cp, ok := help.Value("current_route").(buffalo.RouteInfo); ok { | |
return cp.PathName == name | |
} | |
return false | |
}, | |
// template.html | |
// <div class="menu__item<%= if (isCurrentPathName("rootPath")) { %>--active<% } %>">Home</div> | |
// or | |
// <div class="menu__item<%= if (isCurrentPathName("rootPath")) { "--active" } %>">Home</div> | |
// option 2: | |
// actions/render.go | |
"isActiveMenu": func(name string, help plush.HelperContext) string { | |
if cp, ok := help.Value("current_route").(buffalo.RouteInfo); ok { | |
if cp.PathName == name { | |
return "--active" | |
} | |
} | |
return "" | |
}, | |
// template.html | |
// <div class="menu__item<%= isActiveMenu("rootPath") %>">Home</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment