Skip to content

Instantly share code, notes, and snippets.

@markbates
Last active August 14, 2017 18:53
Show Gist options
  • Save markbates/23acca9a43d16fe2e96cb6b4f834d0fb to your computer and use it in GitHub Desktop.
Save markbates/23acca9a43d16fe2e96cb6b4f834d0fb to your computer and use it in GitHub Desktop.
// 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