I need to display a gallery of photos. So here is my template:
@(photos: List[Photo])
@title = {
<bold>Gallery</bold>
}
@main(title,"photo"){
<ul class="thumbnails">
@for(photo <- photos) {
<li class="span3">
<a href="#" class="thumbnail">
<img src="@photo.path" alt="">
</a>
</li>
}
</ul>
}
And here is my controller method:
public static Result getPhotos() {
return ok(views.html.photo.gallery.render(Photo.get()));
}
And here is my Photo bean :
@Entity
public class Photo extends Model {
@Id
public Long id;
@Required
public String label;
public String path;
public Photo(String path, String label) {
this.path = path;
this.label = label;
}
private static Finder<Long, Photo> find = new Finder<Long, Photo>(
Long.class, Photo.class);
public static List<Photo> get() {
return find.all();
}
public static Photo get(Long id) {
return find.byId(id);
}
public static void create(Photo photo) {
photo.save();
}
public static void delete(Long id) {
find.ref(id).delete();
}
}
I put the photo absolute path in src attribute of img node, but doesn't work. What is the best way to achieve this ?
PS: Image are located outside the play application.