无法在 Magnolia CMS 中渲染上传图片

Can´t render upload images in Magnolia CMS

我在 Magnolia CMS 中有一个内容应用程序,现在我需要从内容应用程序 class DamUploadFieldDefinition 中渲染一张图片

jcr node

我已经在我的 .ftl 中试过了:

<img src = "${cmsfn.link(news.jcrPhoto)}" /> 

但只有 return 照片的路径,无法渲染我的照片

搜索我找到了这个解决方案但没有呈现:

<img src="${damfn.getRendition(news.jcrPhoto, "myAssetVariante").link}" />

我正在查看 MAgnolia 的另一个名为 "contacts" 的内容应用程序,他们通过模型 class:

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 为 null 所以不要传入 if (StringUtils.isNotEmpty(id)) {

所以我硬编码

String id = "651c7140-b681-45b4-8814-ae26bfa0ba0d";

和 运行 所有代码,但 id 不显示 img

Result

正在显示 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="">

但没有功能 请

如果图像在 DAM(资产应用程序)中,试试这个:

<img src="${damfn.getAssetLink(news.jcrPhoto)}">