2015-02-08 68 views
1

比方说,有鉴于文件夹2个阶模板获取斯卡拉模板

  1. file1.scala.html
  2. container.scala.html

现在我想将第一个模板传递给控制器​​的第二个模板(container.scala.html)。像:

public class Application extends Controller { 
    static Result isItPossible() 
    { 
     Result theFile=ok(file1.render()); 
     return ok(container.render(theFile)); 
    } 
} 

这可能吗?如果是这样,我该怎么做?

回答

1

您可以将渲染模板传递给container模板。 container需要有一些Html参数:

container.scala.html:

@(content: Html) 

<p>Here's my content: @content </p> 

而且从控制器内:

public class Application extends Controller { 
    return ok(container.render(file1.render())); 
} 
0

值得一提的是,你并不需要将您的包装容器结合到控制器中,因为模板引擎可以使用布局as described in docs )。在这种情况下,你可以使用它像:

container.scala.html

@()(content: Html) 
<p>Here's my content: @content </p> 

file1.scala.html

@container() { 
    <b>this is content of <i>file1</i> template</b> 
} 

控制器

​​