2011-11-25 3 views
5

나는 그런 식으로하고 싶습니다. 여기 PlayFramework 용 스칼라 템플릿의 동적 매개 변수

는 기본 템플릿입니다 :

@(title: String)(content: Html) 
<!DOCTYPE html> 
<html> 
    <head> 
     <title>@title</title> 
     <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")"> 
     <link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")"> 
     <script src="@routes.Assets.at("javascripts/jquery-1.6.4.min.js")" type="text/javascript"></script> 
    </head> 
    <body> 
     @content 
    </body> 
</html> 

그리고 여기 또 다른 하나입니다

@(user: User) 

@main(title = "@user.email - SiteName") { 

    <b>@user.email (@user.role)</b> 

} 

제목에 "@의 user.email"로 실패하여 이상이 작동하지 않습니다 매개 변수

어떻게하면됩니까?

추신 : 내가 다른 방법으로 이것을 할 수 있음을 알고 있습니다. (주 템플릿에서 "- SiteName"을 추가하십시오) 그러나 이것은 스칼라가 어떻게 작동하는지 이해하는 예제 일뿐입니다.

답변

6

당신은 (이 때문에) 정상 스칼라 코드가 있었다 것처럼 문자열을 연결해야합니다 :

@main(title = user.email + " - SiteName") { 
    <b>@user.email (@user.role)</b> 
} 

모든 @() 내부는 스칼라 코드로 처리됩니다.

+0

이제 분명히 나에게 말한 것처럼 보인다. 고마워. 내가 생각하는 커피가 필요해. :) – Zofren

+0

예, 이미 내 것이 었습니다;) –