如何在scala框架中动态调用函数

如何在scala框架中动态调用函数,scala,intellij-idea,playframework,Scala,Intellij Idea,Playframework,我使用Play framework为IntelliJ Scala中的每个函数创建了单独的文件。如何调用每个函数 @services = { html code of service.scala.html } @navigation ={ html code of navigation.scala.html } 我有contact.scala和更多类似的函数 我的应用程序控制器 object Application extends Controller { def index = Act

我使用Play framework为IntelliJ Scala中的每个函数创建了单独的文件。如何调用每个函数

@services = { html code of service.scala.html  }
@navigation ={ html code of navigation.scala.html } 
我有contact.scala和更多类似的函数

我的应用程序控制器

object Application extends Controller {
  def index = Action {
    Ok(views.html.index())
  }
  def navigation = Action {
    Ok(views.html.navigation())
  }
  def services = Action {
    Ok(views.html.services())
  }
}
我的路线

GET        /                    controllers.Application.index
GET        /navigation          controllers.Application.naigation
GET        /services            controllers.Application.services  

我甚至有一个index.scala.html和main.scala.html。现在,如何在一个页面中调用这些内容?

您可以在任何其他视图中包含已定义的模板。例如,如果视图目录中有services.scala.html,则可以在任何视图中插入以下行:

@views.html.services()

请注意,不必定义路由或动作映射即可将其包含在视图中。

是的,创建一个包含所有其他html内容的模板,如

@(..)(navigation: Html)(services: Html) {
.
.
<html>
  <body>
   @navigation // bring in your individual html contents here or where ever you want.
   @services
   .
   .
  </body>
</html>
}
@(…)(导航:Html)(服务:Html){
.
.
@导航//在此处或任何您想要的地方输入您个人的html内容。
@服务
.
.
}

我必须把这句话放在别的地方吗?如果我正确理解了你的问题,是的,就这些了。如果这不是你想要的,你需要更简单地描述你的问题。我应该在main.scala中调用它吗?你的控制器将调用/呈现html文件,比如index.render(..),如果上面的代码在main.scala.html文件中,它可以调用我上面指定的代码,比如@main(..{..}{..)。