[web-devel] On creating a navigation menu in yesod
Matt Brown
matt at softmechanics.net
Thu Feb 3 07:48:11 CET 2011
I wrote a module to help create navigation menus using jstree[1]. The
key interface is:
data Nav y = Nav {
navTitle :: String
, navRoute :: Route y
}
navTitle :: Route y -> GHandler sub y String
navChildren :: Route y -> GHandler sub y [Nav y]
navTitle is used when rendering the initial tree (with the node for
the current page collapsed). Expanding a node calls navChildren via
ajax to get the children.
If anyone's interested, I can put it up somewhere with an example tomorrow.
-matt
[1] http://www.jstree.com/
On Wed, Feb 2, 2011 at 8:00 PM, Michael Snoyman <michael at snoyman.com> wrote:
> 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
>>
>
> _______________________________________________
> 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