-2

I am currently learning about the play framework and I have seen in a couple of tutorial videos people using @ before declarations.

For example, in the index.html file:

@main 

or @ message

What does @ do? How is it used in the html files? It reminds me a lot of the $ in JQuery.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Imago
  • 521
  • 6
  • 29
  • Those are all different usages. Please be more specific. – Sotirios Delimanolis Jun 06 '16 at 21:19
  • 1
    I think the author means the `@` used in Play Framework templates: https://www.playframework.com/documentation/2.5.x/ScalaTemplates#Overview vs the `@` in scala (or java?) source. So it's not a duplicate. – pedrofurla Jun 06 '16 at 21:23
  • @pedrofurla if you could edit this question to explain that, it would greatly help the OP. Right now it's hard to tell what the question is asking about. – ryanyuyu Jun 06 '16 at 21:41
  • @pedrofurla If you feel comfortable doing so, please edit the question to address playframework. If that's what this question is about, I don't see the relevance of mentioning Java and its annotations. We can then vote to reopen. It's currently unclear. – Sotirios Delimanolis Jun 06 '16 at 21:42
  • @ryanyuyu, I believe my question to be rather clear. Also it is pretty hard to be more specific and elite, if one doesn't know what to look for. + nobody expects you to give a full & perfect answer, that teaches me everything about programming.. if you wanted me to do research myself, well yes, however finding something, when you don't look for what is kinda hard + googling for @ is not necessarily helpful at all. – Imago Jun 07 '16 at 13:45
  • @biesior From their comments and title, I am confident, yes. If it was asking about both annotations and playframework's dynamic statements, you should've left the question closed as a duplicate for Java and asked OP to ask another question about playframework. We already have an answer for Java. I couldn't find one for playframework. This can act as a good canonical for that. You should edit your question to only address the playframework syntax. – Sotirios Delimanolis Jun 07 '16 at 17:11
  • @biesior You'll notice that is the first thing I asked of them and they refused. – Sotirios Delimanolis Jun 07 '16 at 17:32
  • @SotiriosDelimanolis and OP didn't understand your intentions, therefore I tried to explain it in basic words, anyway I didn't ask you if you are sure to offend you, just was considering if you maybe know something more, that caused you changed the post so much... anyway we're just spamming the post ;) I'm gonna to delete most of the comments and let the OP to spell-out himself ;) – biesior Jun 07 '16 at 17:38

1 Answers1

0

In first case i.e. @Entity or @Id these are Java annotations - they are used in the Java classes for different purposes (according to their destination). You probably showing as a part of Ebean model, check its docs to see what they do, sample:

package models;

import java.util.*;
import javax.persistence.*;

import com.avaje.ebean.Model;
import play.data.format.*;
import play.data.validation.*;

@Entity
public class Task extends Model {

    @Id
    @Constraints.Min(10)
    public Long id;

    @Constraints.Required
    public String name;

    public boolean done;

    @Formats.DateTime(pattern="dd/MM/yyyy")
    public Date dueDate = new Date();

    public static Finder<Long, Task> find = new Finder<Long,Task>(Task.class);
}

Second at used in the Twirl templates indicates the named variable or beginning of the dynamic statement in general i.e.:

<title>@pageTitle</title>
<ul>
  @for((item, index) <- myItems.zipWithIndex) {
    <li>Item @index is @item</li>
  }
</ul>

Where @pageTitle, @index and @item = varaibles,
@for(...){ ... } it's just a loop's block, observe that myItems dosen't require the @ symbol, as it's recognized as Scala argument)

It's described in the Twirl documentation

As you can see @ char in both cases hasn't any connection, they has absolutely different meaning.

To get better understanding first get familiar with linked Twirl documentation, and with Play documentation in general. Then study several sample apps from prepared by Play team, to realize which is which.

biesior
  • 55,576
  • 10
  • 125
  • 182