[web-devel] On creating a navigation menu in yesod

Rafael Cunha de Almeida rafael-lists at kontesti.me
Thu Feb 3 04:53:28 CET 2011


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

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?


More information about the web-devel mailing list