Scara 템플릿을 이해하면서 템플릿의 HTML 해석

5832 단어 Scalatech
Django, Laravel 등 템플릿 엔진을 갖춘 프로그램 라이브러리가 많이 왔지만, scala의 템플릿 엔진은 한꺼번에 보기 어려울 것 같다
이번 목표는 이쪽을 이해하는 거예요main.scala.html
@*
 * This template is called from the `index` template. This template
 * handles the rendering of the page header and body tags. It takes
 * two arguments, a `String` for the title of the page and an `Html`
 * object to insert into the body of the page.
 *@
@(title: String)(content: Html)

<!DOCTYPE html>
<html lang="en">
    <head>
        @* Here's where we render the page title `String`. *@
        <title>@title</title>
        <link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
        <link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">

    </head>
    <body>
        @* And here's where we render the `Html` object containing
         * the page content. *@
        @content

      <script src="@routes.Assets.versioned("javascripts/main.js")" type="text/javascript"></script>
    </body>
</html>

이 문서의 출처


이 파일은play-sala-seed 템플릿sbt new을 사용하면view에 있습니다.

시작 - 매개변수 섹션


먼저 설명문을 쓰다.
@*
 * This template is called from the `index` template. This template
 * handles the rendering of the page header and body tags. It takes
 * two arguments, a `String` for the title of the page and an `Html`
 * object to insert into the body of the page.
 *@
이 템플릿은 색인 템플릿에서 가져옵니다.이 템플릿은 페이지의 눈썹과 바디 탭을 조작하는 데 사용됩니다.매개 변수 중
  • 페이지 제목(문자열)
  • 바디 태그의 내용(HTML 객체)
    필요
  • 여기까지 열심히 써주셔서 감사합니다.앞으로 걸어가다
    매개변수는 다음과 같습니다.
    @(title: String)(content: Html)
    
    참고로 댓글은 @* *@로 썼어요.

    HTML 섹션


    <!DOCTYPE html>
    <html lang="en">
        <head>
            @* Here's where we render the page title `String`. *@
            <title>@title</title>
            <link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
            <link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
    
        </head>
        <body>
            @* And here's where we render the `Html` object containing
             * the page content. *@
            @content
    
          <script src="@routes.Assets.versioned("javascripts/main.js")" type="text/javascript"></script>
        </body>
    </html>
    
    모양은 거의 일반 HTML입니다.scala 템플릿에서 다섯 번째 줄 @title 과 12 줄 @content 처럼 @ 뒤에 변수 이름을 기술합니다.

    href 속성의 @routes.Assets.versioned의 기술


    기본적으로 @routes.Assets.면public 폴더를 볼 수 있습니다.즉, 공공 폴더 아래는 이렇다.어떻게 조작해야 할지 알기 전에 정부에서도 이 사용법을 추천합니다
    public
    - javascripts
    - stylesheets
    - images
    
    controllers.routes.Assets에서 설정된Assets 폴더에 지정한 경로와 이 기술을 변환하는 컨트롤러를 만들었습니다. 구축할 때 설정된 경로로 바꾸는 구조인 것 같습니다.

    참조 페이지


    https://www.playframework.com/documentation/ja/2.2.x/ScalaTemplates
    https://www.playframework.com/documentation/ja/2.4.x/Assets#WebJars
    https://www.playframework.com/documentation/ja/2.4.x/Assets#자원 의 역방향 루트 를 공개 하다

    좋은 웹페이지 즐겨찾기