Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Play框架中的变量中获取scala模板_Java_Scala_Playframework - Fatal编程技术网

Java 在Play框架中的变量中获取scala模板

Java 在Play框架中的变量中获取scala模板,java,scala,playframework,Java,Scala,Playframework,假设视图文件夹中有两个scala模板 file1.scala.html container.scala.html 现在我想将第一个模板从控制器传递到第二个模板(container.scala.html)。比如: public class Application extends Controller { static Result isItPossible() { Result theFile=ok(file1.render()); return o

假设视图文件夹中有两个scala模板

  • file1.scala.html
  • container.scala.html
  • 现在我想将第一个模板从控制器传递到第二个模板(container.scala.html)。比如:

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

    可能吗?如果是,我如何做?

    您可以将渲染的模板传递给
    容器
    模板<代码>容器
    需要一些
    Html
    参数:

    container.scala.html:

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

    值得一提的是,您不需要在控制器中组合包装容器,因为模板引擎能够使用布局()。在这种情况下,您可以这样使用它:

    container.scala.html

    @()(content: Html)
    <p>Here's my content: @content </p>
    
    @container() {
        <b>this is content of <i>file1</i> template</b>
    }
    
    @container() {
        <b>this is content of <i>file1</i> template</b>
    }
    
    public class Application extends Controller {
        static Result itIsPossible() {
            return ok(file1.render());
        }
    }