Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

java - Can't find view in subfolder

I just started using the Play2.0 Framework and I'm trying to use the main template in my home/index template. The issue I'm having is it can't find "main" when its in the Shared folder, if I take it out and put it in the Views root then it works fine.

So I'm wondering how I can reference the main.scala.html from index.scala.html?

My folder structure is as follows:

  • Views
    • Home
      • index.scala.html
    • Shared
      • main.scala.html

My code in index.scala.html is:

@head = {

}

@content = {
    <b>Home Screen</b>!!
}

ERROR: @main(title = "Home",head, content)

The error I get is:

not found: value main.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use:

@Shared.main(title = "Home",head, content)

For security and performance reasons Play compiles templates to Scala functions and stores it in managed folder /target/scala-2.9.1/src_managed/main/views, so you can preview it to find correct path.

rules are easy for view files saved with pattern:

  • /app/views/viewName.scala.ext (where ext can be html, xml or txt) Play will compile views to: view.ext.viewName
  • and for /app/views/SomeSub/OtherSub/viewName.scala.ext it will be: view.ext.SomeSub.OtherSub.viewName

so:

/app/views/general.scala.html             = views.html.general
/app/views/Main/index.scala.html          = views.html.Main.index
/app/views/Api/usersList.scala.xml        = views.xml.Api.usersList
/app/views/Email/English/body.scala.txt   = views.txt.Email.English.body

etc...

There is some case with /app/views/tags package which is auto imported to the views, so you can use /app/views/tags/myTag.scala.html just with: @tags.myTag(args) syntax in any view.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...