Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Access attachment url from multiple attachments View modes: 
User avatar
Member
Member
eric.savage-clyral - 11/7/2012 4:49:29 AM
   
Access attachment url from multiple attachments
We have an article document type where the user can provide a body text and multiple attachments on a Document Attachments field.

Our client wants to support the scenario where there is no body text and a single attachment, so linking to the article opens the attachment immediately.

I am looking at the macro transformations GetFireUrl and GetAttachmentUrl, but they are designed for fields with a single upload file. Is there some macro I can use to access individual items within a multiple attachments field (in this case the first and only attachment where there is only one attachment)?

User avatar
Kentico Support
Kentico Support
kentico_janh - 11/8/2012 6:44:06 AM
   
RE:Access attachment url from multiple attachments
Hello,

If you want to get the first attachment of given document, you can use following macro:
CurrentDocument.Attachments.FirstItem.AttachmentGUID

In case the attachment is an image, you can display it like this:
<img src="~/getattachment/{%CurrentDocument.Attachments.FirstItem.AttachmentGUID%}" />

Best regards,
Jan Hermann

User avatar
Member
Member
eric.savage-clyral - 11/8/2012 8:37:42 AM
   
RE:Access attachment url from multiple attachments
If I put that in the transformation, I get the following in the view:

{%CurrentDocument.Attachments.FirstItem.AttachmentGUID%}

I don't think I understand all the technology here. If you're using the transformation inside a repeater, does CurrentDocument still apply? Also, you're referring to the property "Attachments", but as I suggested, I'm looking at a field that is of type "Document attachments", not the Attachments you add under the Properties tab in the CMS Desk.

What I need exactly is:
- inside the transformation used for a repeater, to access the field of type document attachments, and access the first attachment in the list
- "GetFileUrl" works for a field of type File, but not of type Document Attachments

User avatar
Kentico Support
Kentico Support
kentico_janh - 11/26/2012 2:04:15 AM
   
RE:Access attachment url from multiple attachments
Hello,

I just want to inform you that from the new hotfix (7.0.10) there is a new property GroupedAttachments where these attachments are listed, so you can use following macro to get their URLs:

{% GetAttachmentUrl(Documents["/home"].GroupedAttachments.test["image.JPG"].AttachmentName, Documents["/home"].NodeAliasPath) %}


Best regards,
Jan Hermann

User avatar
Member
Member
eric.savage-clyral - 11/26/2012 3:02:38 AM
   
RE:Access attachment url from multiple attachments
Thanks for your help