0

How to declare val or var in view template? I've have tried below code but looks like play scala can't recognize it and getting error

"not found: value snoops"

<div class="thumbImg">
        @{val snoops: Object= Snoop.findOneById(activity.activities.head.snoopId)}
        @snoops.userId
</div>
1

2 Answers 2

2

Valid way to do that is using defining as showed in docs, anyway often it's better to do that in the controller and then pass to view as an argument.

3
  • thanks, now the result is : Snoop(5327e4c19b82377ee0c85f65,5327e4b99b82377ee0c85f63,5023cb91e4b0c82863a116c3) the code is : @defining( Snoop.findOneById(activity.activities.head.snoopId) ) { snoop =>@snoop} Question : how can I access the 2 value?
    – Monnster
    Mar 21, 2014 at 13:16
  • Use { snoop =>@snoop.userId}
    – biesior
    Mar 21, 2014 at 13:23
  • tried that already and getting : value userId is not a member of Option[models.Snoop] Here my DB: { "_id": ObjectId("5327e4c19b82377ee0c85f65"), "_t": "models.Snoop", "propertyId": ObjectId("5327e4b99b82377ee0c85f63"), "groupId": ObjectId("5023cb91e4b0c82863a116c3"), "userId": ObjectId("5023cb91e4b0c82863a116c1")
    – Monnster
    Mar 21, 2014 at 13:35
0

try this in scala template

@import java.math.BigInteger; val i=1; val k=1

if you want string then

@import java.lang.String; val name="template"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.