问题描述:

Here below is a template for generating a HTML email... and I want to put the current time in the body according to the user's timezone:

@(user: models.auth.User)(implicit request: RequestHeader, lang: Lang)

@import org.joda.time.{DateTime, DateTimeZone}

@import org.joda.time.format.DateTimeFormat

...

@user.timeZone.map { tz =>

var timeZone = DateTimeZone.forId(tz)

val formatter = DateTimeFormat.mediumDateTime.withZone(timeZone)

val currentTime = formatter.print(DateTime.now)

<p>@Messages("email.timestamp", currentTime)</p>

}

<p>@Messages("email.salutation")</p>

The code above does not compile because the compiler doesn't find currentTime when invoking @Messages.

What's the syntax to pass currentTime to @Messsages?

网友答案:

Try

@defining({ // code computing time }) { currentTime =>

@currenTime

}

相关阅读:
Top