简体   繁体   中英

How to call pages dynamically play scala using Intellij idea

I have uploaded a simple web template in play Scala using intellij idea. how to call each section from different file, I am calling each function from index.scala.html this is my main.scala.html

    <html>
    <body  id="page-top" class="index">
       @navigation
          @header
             @services
                  @portfolio
                         @about
                         @team
                  @client
             @contact
          @footer
 </body>
 </html>

As the above code how to have each function that is @services in separate file, @portfolio in separate file . this is my index.scala.html

  @(message: String)

   @navigation = { navigation html code}

     @header = {<header> html code</header>}
      @services = {

       <section id="services"><!--html code for reference-->
        <div class="container">
         <div class="row">
          <div class="col-lg-12 text-center">
            <h2 class="section-heading">Services</h2>

          </div>
         </div>
       <div class="row text-center">
        <div class="col-md-4">
            <span class="fa-stack fa-4x">
                <i class="fa fa-circle fa-stack-2x text-primary"></i>
                <i class="fa fa-shopping-cart fa-stack-1x fa-inverse"></i>
            </span>
            <h4 class="service-heading">E-Commerce</h4>

        </div>
        <div class="col-md-4">
            <span class="fa-stack fa-4x">
                <i class="fa fa-circle fa-stack-2x text-primary"></i>
                <i class="fa fa-laptop fa-stack-1x fa-inverse"></i>
            </span>
            <h4 class="service-heading">Responsive Design</h4>

        </div>
        <div class="col-md-4">
            <span class="fa-stack fa-4x">
                <i class="fa fa-circle fa-stack-2x text-primary"></i>
                <i class="fa fa-lock fa-stack-1x fa-inverse"></i>
             </span>
            <h4 class="service-heading">Web Security</h4>

        </div>
      </div>
     </div>
     </section>

    }
@main("hello test")(navigation)(header)(services){  }

my application package controllers

  import play.api._
  import play.api.mvc._

  object Application extends Controller {
  def index = Action {
  Ok(views.html.index("Ok"))
      }
   }

my routes

   GET        /                    controllers.Application.index

I wanted header to be in same file ., make @services @portfolio into different different files and call them as one page web page dynamically.

I know one solution. You have to create one file per function.

navigation.scala.html

@()
navigation html code

header.scala.html

@()
<header> html code</header>

And other. You can create it in separate package/folder (mainscala) and import all files:

@import views.html.mainscala._

And add brackets:

<html>
    <body  id="page-top" class="index">
       @navigation()
          @header()
....
    </body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM