Skip to content

Instantly share code, notes, and snippets.

@mguillermin
Created March 21, 2012 06:32
Show Gist options
  • Save mguillermin/2145305 to your computer and use it in GitHub Desktop.
Save mguillermin/2145305 to your computer and use it in GitHub Desktop.
Play 2.0 Template inclusion with "backed" logic
@main("Welcome"){
...
@controllers.Menu.render("home")
...
}
package controllers;
import play.api.templates.Html;
import models.MenuItem;
public class Menu {
public static Html render(String parent) {
List<MenuItem> menuItems = MenuItem.findByParent(parent);
// more business logic...
return views.html.menu.render(menuItems);
}
}
@(menuItems: List[MenuItem])
<h2>The Menu</h2>
<ul>
@for(menuItem <- menuItems) {
<li><a href="@menuItem.url">@menuItem.title</a></li>
}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment