Play! Frame: layouts with various sections

I have a problem trying to use layouts on Play! Framework As far as I know, the layout has a SINGLE #{doLayout /} tag, which indicates where all the code of the child view should be placed. This means that all the code in a specific view, for example, the Users list (list.html), is entered in the middle of the layout body. Now, I have found that some of my views require javascript, which is special for these views, so I would like to include script tags only in these views, and not on every view that inherits from the layout. The Razor viewer in ASP.NET MVC allows you to use different sections in a layout that are populated with 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?

+4
source share
2 answers

You can also use # get, # set tags to define other blocks. For instance:

 #{set 'anyBlock'} <h1>Main title</h1> #{/set} 

and

 #{get 'anyBlock' /} 
+9
source

You can use the script tag in your specific views. For instance:

 #{script 'jquery.js' /} 

I recommend you read this documentation page:

http://www.playframework.org/documentation/1.1/tags#script

+1
source

All Articles