我在Magnolia CMS中有一个内容应用程序,现在我需要从内容应用程序中重新编写DamUploadFieldDefinition类的图像
我在.ftl中试过这个:
<img src = "${cmsfn.link(news.jcrPhoto)}" />
但只返回照片的路径而无法渲染我的照片
搜索我找到了这个解决方案,但没有呈现:
<img src="${damfn.getRendition(news.jcrPhoto, "myAssetVariante").link}" />
我正在寻找另一个名为“联系人”的MAgnolia内容应用程序,他们通过模型类来实现:
public class NewsModel<RD extends TemplateDefinition> extends AbstractSTKTemplateModel<TemplateDefinition> {
private Node news;
@Inject
public NewsModel(Node content, TemplateDefinition definition, RenderingModel<?> parent,
STKTemplatingFunctions stkFunctions, TemplatingFunctions templatingFunctions) {
super(content, definition, parent, stkFunctions, templatingFunctions);
System.out.println("Entramos en el constructor");
}
/**
* FIXME: should be done better (binaryHandling): SCRUM-525.
*/
public String getPhoto() {
System.out.println("BOB inicio en el getPhoto");
if (news == null) {
System.out.println("news == null");
return null;
}
Property binaryData = null;
try {
if (news.hasNode("photo")) {
System.out.println("Tenemos contenido");
Node binaryNode = news.getNode("photo");
binaryData = binaryNode.getProperty("jcr:data");
}
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
if (binaryData != null) {
System.out.println("retornamos desde templatingFunctions");
return templatingFunctions.link(binaryData);
} else {
System.out.println("retornamos null");
return null;
}
}
public ContentMap getNews() {
System.out.println("Inicio getNews");
ContentMap cm = templatingFunctions.asContentMap(news);
System.out.println("ContentMap=\n"+cm);
return cm;
}
public void setNews(Node news) {
this.news = news;
}
@Override
public String execute() {
System.out.println("En el execute");
try {
NodeIterator ni = content.getNodes();
System.out.println("size:"+ni.getSize());
while(ni.hasNext()){
System.out.println(ni.toString());
Node n = ni.nextNode();
System.out.println(n.getIdentifier());
}
} catch (RepositoryException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//String id = PropertyUtil.getString(content, "news");
String id = "651c7140-b681-45b4-8814-ae26bfa0ba0d";
news = null;
System.out.println("id="+id);
if (StringUtils.isNotEmpty(id)) {
System.out.println("En el if del execute");
try {
news = new HTMLEscapingContentDecorator(true).wrapNode(NodeUtil.getNodeByIdentifier("news",id));
}
catch (RepositoryException e) {
System.out.println("Can't get uuid: '" + id + "' of contact.");
}
}
return super.execute();
}
}
我的FTL是:
[#assign news = model.news!]
7
[#if news?has_content]
8
[#assign hasPhoto = model.photo?has_content]
[/#if]
[#if contact?has_content]
9
[#if hasPhoto]
10
<dl class="media photo pos-2">
<dt><img src="${model.photo}"/></dt>
</dl>
[/#if]
[/#if]
当我提出String id = PropertyUtil.getString(content, "news");
ID为空时,请不要传入if (StringUtils.isNotEmpty(id)) {
所以我硬编码
String id = "651c7140-b681-45b4-8814-ae26bfa0ba0d";
并运行所有代码但id不显示img
显示Google的控制台我可以看到图片路径:
/mgnl-prosegur-intra-webapp/01/photo
但即使像我的图像名称那样使用联系人内容应用程序的src,也不要显示任何内容
<img src="/mgnl-prosegur-intra-webapp/demo-project/contacts/ldavinci/photo/vitruviano.jpeg" alt="">
更改为:
<img src="/mgnl-prosegur-intra-webapp/demo-project/contacts/ldavinci/photo/vitruviano.jpeg" alt="">
但不是功能 请
答案 0 :(得分:2)
如果图片在DAM(资产应用)中,请尝试以下操作:
<img src="${damfn.getAssetLink(news.jcrPhoto)}">