Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of a menu/submenu #210

Closed
egonelbre opened this issue Jul 8, 2013 · 3 comments
Closed

Example of a menu/submenu #210

egonelbre opened this issue Jul 8, 2013 · 3 comments

Comments

@egonelbre
Copy link

One common problem that people will try to implement is a menu/submenu. Although it's not too hard, but maybe samples how to do it would be beneficial. I thought of two ways - define menu on the view, and pass the focused item as a parameter to the renderer; define a filter that attaches a menu information to the controller and use that to build the menu. Also is there some recommended way of doing it?

@robfig
Copy link
Contributor

robfig commented Jul 9, 2013

Hm, that would be a helpful to have in a sample app. I think there are many ways to do it...

  1. Potentially the easiest would be if a Controller corresponded to a single menu tab. Then you could have the template know which one is selected by the controller name, which could be added to RenderArgs before every request (if it's not already available there somehow).
  2. You could potentially have a map from Controller name to Menu item, and look it up to get the selected item
  3. Add a Menu struct { Item1, Item2, Item3 bool } to the RenderArgs, and set the appropriate one in the action or interceptor
  4. Use a variable set in the template , e.g.

Page:

{{set . "menuItem" "ItemName"}} 
{{template "menu.html" .}}

Menu.html:

{{if eq .menuItem "Item1"}} Item 1 selected {{end}}
{{if eq .menuItem "Item2"}} Item 2 selected {{end}}

I think there's more ways and variations. Does this help?

@egonelbre
Copy link
Author

Mix between 1&3 looks like a solid solution...

My issue wasn't "I don't know how to do it" - it's more of "it would help newcomers to have examples of it"; and just a general question on different ways on how to do it. :)

thanks :)

@brendensoares
Copy link
Member

@egonelbre I agree that it's not very obvious how to do what you were asking; it requires that a new Revel user get familiar with Go's template package. Hopefully when we add support for other more common 3rd party templating engines it will be more obvious. I'm sure we'll also add some clear instructions in the manual (and ideally some tutorial videos, too!).

Thanks for being part of the Revel community and contributing your feedback and ideas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants