Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 560
Diego Avatar asked Dec 29 '22 04:12

Diego


1 Answers

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

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

and:

#{get 'anyBlock' /}
like image 197
Guillaume Bort Avatar answered Jan 08 '23 14:01

Guillaume Bort