Replies: 1 comment 2 replies
-
Hey! 👋 From my experience, this is something that varies greatly from one project to another. Inferring the current navigation item from route namespaces could work for some projects, but for some others with different behaviours and implementations, it could not work at all afaics! This is also something that can be implemented very easily by defining a concern module and having handlers define which "navigation section" they are associated with. This is the approach used by the Marten Realworld demo application. For example: module NavBarActiveable
macro included
class_getter nav_bar_item : String?
extend NavBarActiveable::ClassMethods
before_render :add_nav_bar_item_to_context
end
module ClassMethods
def nav_bar_item(item : String | Symbol)
@@nav_bar_item = item.to_s
end
end
private def add_nav_bar_item_to_context
context[:nav_bar_item] = self.class.nav_bar_item
end
end
class MyHandler < Marten::Handler
include NavBarActiveable
nav_bar_item :posts
end Then in your templates you can simply make use of the But we could indeed ensure the resolved route name is added to |
Beta Was this translation helpful? Give feedback.
-
It can be useful for highlighting currently active route in navigation sections.
When using route groups (e.g.
posts:list
,posts:detail
), it should matchposts
for bothposts:list
andposts:detail
, so if the route is inside the group, it matches the route group name.If
Marten::Routing::Map#resolve
would return the route name too, that could be used.Also, a template tag would be useful:
{% current_route_matches "posts" %}
.Beta Was this translation helpful? Give feedback.
All reactions