简体   繁体   中英

compose a page from different resources scala template In play! 2.0

If I have A main page which composed from more than one section (header,main,side,etc..),each Is loaded from different URL say header Is composed from /head side section Is loaded from /side we used to use Include in other frameworks.how can I do this In play! 2.0 I used Jquery to do It but can't this be done natively

$.get("/hello", function(result){
      $("#xxx").html(result);

As said by Marcus, this is detailed in official documentation .

In fact, you do not paste together results from different URL. You define in your template which templates have to be used.

You can include other templates using :

<h1>Home</h1>

<div id="side">
  @common.sideBar()
</div>

But if you plan to have a global frame surrounding your pages, you should have a look to extended template :

@otherTemplate("Title"){

   //Html content here ...

}

Update :

if what you are trying to do is retrieve an absolute URL from a controller, you have to use the reverse routing :

@routes.Application.hello("Bob").absoluteUrl()
<div id="side">
  @common.sideBar()
</div>

BTW it's from official documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM