Play 2 Framework, Templates and Javascript

I am writing an application that makes extensive use of both Play 2 templates and Javascript.

I am intermingling the two together in a single file, but in doing this, I get a variety of errors and warnings.

For example, a simple object literal variable declaration, which I want to be set to data loaded from the server, such as this:
     times: @Html(CampaignDetailHelper.dayPartTimesJson)
Gives me the error "Statement Expected"

A more complex intermingling, such as this:
     var partTypes = [];
     @for(dayPartType <- DayPartType.values) {
               ordinal: "@dayPartType.ordinal",
               value: "@(dayPartType.toString)",
               label: "@(dayPartType.toString)"
     DayParts.partTypes = partTypes;

Leads to an error on the last statement - the period between DayParts and partTypes is highlighted and flagged with the message ": expected".

There are other issues I'm observing as well.

I'm sure this is probably difficult to handle within an IDE, but I'd love to hear what the best practices are for doing this sort of mixing. I would really like to take advantage of the Javascript syntax highlighting, code completion and code documentation features provided by IntelliJ, even if it means doing some convolutions. Right now, I basically might as well turn the Javascript-related features off, because there are far too many false errors.


Please sign in to leave a comment.