I got the url like “/site/binaries/content/documents/portal/department/it/it/portal%3AuploadFiles”, but acturally it is a pdf file named “test.pdf”. I don’t know how to make a donwload link of the document in freemarker…
Actually, I think the correct method here might be org.hippoecm.hst.content.beans.standard.HippoItem#getChildBeansByName(java.lang.String, java.lang.Class) rather than getChildBeans. The first method allows you to give child node name, which is proabbly what you want here. Otherwise you may get more beans than you want (if there are other resource nodes in a different compound).
I’ve tried your ftl code and it works correctly for me.
I created an archetype project, added Simple Content via essentials, added a resource compound via document type editor, made it multiple. Adjusted a document to have resources. Used BeanWriter and adjusted the code to work with getChildBeansByName. Added your ftl to the template (contentpage-main.ftl), wihtout the var so it just prints. The correct urls are generated.
Could you try that in an archetype? It should work.
The “getChildBeansByName” really worked, but there’s still the problem for freemarker template.
Could you please try the following code, and check whether the html link works or not?
<#list document.uploadFiles as file>
<@hst.link var=“fileURL” hippobean=file/>
<a href="${fileURL}">
${file.filename}
</a>
</#list>
I think the code is just the same as the one of getting linked images, but for resources, I cannot get the documents (pdf files in my case).
But the url losts filename info. When right clicking the link and then saving the file, the name of the saved file is without any extension (.pdf. jpg and so on). The user may not know what the document is.
The problem is that links are generally generated as paths. In the assets folder the filename is part of the path, but in document the path is “myproject:resource”. You should be able to influence this with custom binary link generation.