Could not find view in subfolder

I just started using the Play2.0 platform, and I'm trying to use the main template in my home/index template. The problem that I encountered cannot find the โ€œmain thingโ€ when it is in the shared folder, if I pulled it out and placed it in the โ€œViewsโ€ root directory, then it works fine.

So, I am wondering how can I link to main.scala.html from index.scala.html ?

My folder structure is as follows:

  • Views
    • home
      • index.scala.html
    • General
      • main.scala.html

My code in index.scala.html :

 @head = { } @content = { <b>Home Screen</b>!! } ERROR: @main(title = "Home",head, content) 

The error I am getting is:

 not found: value main. 
+2
source share
2 answers

Once you get into the subfolders for viewing, it looks like a "pseudo-package" called "html". I'm not quite sure how this works, but try the following:

 @views.html.Shared.main 
+1
source

You can use:

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

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

rules to easily view files saved using a template:

  • /app/views/viewName.scala.ext (where ext can be html , xml or txt ). Playback will compile the views: 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 the package /app/views/tags , which is automatically imported into the views, so you can use /app/views/tags/myTag.scala.html with only the syntax: @tags.myTag(args) in any view.

+6
source

Source: https://habr.com/ru/post/977736/


All Articles