java - Does Play Framework support "snippets"? -
if want have common piece of ui across multiple pages, such menu, recommended way this?
it contain both template code , back-end controller (similar "snippets" in liftweb framework).
i aware there menu module play, i'm more interested in how achieved in general.
there 2 ways include common view code play framework.
you can use #{include}
tag or #{extends}
tag.
the extends tag, name suggests, extends parent view. extends tag used default in skeleton code set play when create new application. extends main.html. add code here.
the includes tag, allows inject common piece of view code templates @ specified point. works in same php include/require, or jsp includes work.
the problem come when template code requires data or logic model (via controller). if case, need use @before or @with notation in controller ensure common piece of controller code executed each time. can add data renderargs list, available use within view.
a simple example of using renderargs be.
@before private static void commondata() { // logic here renderargs.put("menu", menu); renderargs.put("selected", selectedmenuitem); }
the values have put renderargs (menu , selected in example) available in same way if passed them render method.
Comments
Post a Comment