Play! Framework: Layouts with different sections
I'm having a problem when trying to use layouts in the Play! Framework. As far as I know, a layout has a SINGLE #{doLayout /}
tag that specifies where all the code of the child view should be placed. This means that all the code in a particular view of, say, list of Users (list.开发者_如何学编程html) gets injected in the middle of the body of the layout. Now, I find that some of my views require javascript that is particular to those views, and so I'd like to include script tags only on those views and not on every single view that inherits from the layout. The Razor view engine in ASP.NET MVC allows for different sections in a layout that are filled in by a view that extends that layout, but I don't know if Play supports something like this.
Do you see a solution to this problem?
You can also use the #get,#set tags to define other blocks. For example:
#{set 'anyBlock'}
<h1>Main title</h1>
#{/set}
and:
#{get 'anyBlock' /}
You can use the script tag in your specific views. For instance :
#{script 'jquery.js' /}
I recommend you to read this documentation page :
http://www.playframework.org/documentation/1.1/tags#script
精彩评论