我是CQ5的新手,我遇到了以下问题。CQ5 - 如何获取页面图片
我试图显示一个列表与子页面后面的图像。我设法让列表本身工作,但图像出现问题,路径不正确。
到目前为止,我已经有了这个
<div class="img-list">
<img src="${list.img}" />
</div>
和
public class ImageList {
private String img = "";
private Page listItem;
String extension;
Resource r;
public ImageList(Page p) {
this.listItem = p;
this.r = listItem.getContentResource("image");
}
public String getImg() {
if (r != null) {
//Image image = new Image(r);
img = r.getPath();
}
return img;
}
public void setImg (String i) {
this.img = i;
}
}
但是,这是行不通的。有人可以帮我吗?
在此先感谢
编辑,得到了它与下面的解决方案工作:
public String getImg() {
String imagePath = "";
if (r != null) {
Image image = new Image(r);
imagePath = (String)listItem.getPath()+".img.png"+ image.getSuffix();
}
return imagePath;
}
让孩子不是问题。问题是显示图像。我刚刚尝试了一些您的解决方案的修改版本,输出为。另外,我并不想从当前页面获取孩子。我正在使用不同页面的孩子。 –
Nevermind,发了一个小的错字,我刚刚使用了String imagePath =(String)contentpage.getPath()+“。img.png”+ image.getSuffix();在我原来的解决方案,它的工作,谢谢! –