[web-devel] On creating a navigation menu in yesod
Michael Snoyman
michael at snoyman.com
Thu Feb 3 05:00:39 CET 2011
I think the function getCurrentRoute[1] will help you out here. It
will return Maybe (SiteRoute); the Maybe for the case where you're
dealing with a 404 response. Just compare each route against the
result.
Now if you need something more complicated like menu hierarchies, I
would recommend YesodBreadcrumbs, but for your use case I think this
is sufficient.
Michael
[1] http://hackage.haskell.org/packages/archive/yesod/0.6.7/doc/html/Yesod-Handler.html#v:getCurrentRoute
On Thu, Feb 3, 2011 at 5:53 AM, Rafael Cunha de Almeida
<rafael-lists at kontesti.me> wrote:
> Hello,
>
> I'm trying to create a navigation menu in yesod. First I thought about creating
> a widget. But, afaik, I'd need to add it in each handler of the site, after
> all, the menu should be always visible.
>
> So I ditched that approach. I wrote the menu code right in
> default-layout.hamlet. I wrote a loop that iterates over menuRoutes, which is a
> list of tuples composed of route and the menu name for that route. Like this:
>
> menuRoutes = [(RootR, "Home"), (TeamR, "Team")]
>
> During the iteration I add each of those. I created that in Site.hs, right after
> mkYesodData. The problem with that approach is that the link for the current
> site should be disabled. So, if we're at RootR, then there should be a
> <b>Home</b> in the menu instead of <a href="/">Home</a>. That's where I got
> stuck.
>
> I can't really pass anything to defaultLayout when I'm at the handler function
> and there doesn't seem to be the information of which handler was executed to
> create the current view. I thought the information could be in the Foundation
> (via getYesod), but I couldn't find anything. What's the recommended way of
> creating such menus?
>
> []'s
> Rafael
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
More information about the web-devel
mailing list