I am having an issue with the Collection Display fragment. My Liferay version is 7.4 CE ga129 German. I have a mixed asset list with web content articles and documents, mainly PDFs. On my page, the title should be linked to the article or document. In the mapping column, I have selected Title as the assignment, Assigned URL for the link, and Display Page URL for the URL field, as shown in the picture.
Web content articles are linked, but the documents are not, perhaps because there is no display page for them. If possible, the link to the document should open it directly in the browser. In other words, it should not be offered for download or shown in the Liferay preview.
Is there a smart solution for this? Or is my only option to work with separate asset lists for web content and documents?
Thanks for joining Discuss, and thanks for your question.
You’ve kind of already answered it yourself really - the field you’ve mapped to for the link is the “Display Page URL” which will redirect the user to the Display Page of the asset in question. If you don’t have a Display Page Template created for Documents, unfortunately the asset won’t have a Display Page URL, hence no link.
Because different types of assets have different fields and metadata, when you have a single Collection with multiple asset types in it there’s a limited amount of common fields available. There’s not really a way that Liferay could simply infer what you want to do. Documents are kind of a special case because in some cases you might want to trigger a download of the file, in some cases (like yours) you may want to render in the browser (and even this is tricky to control because different browsers process PDFs differently - they may have a built in renderer, the user might have installed the Adobe Acrobat plug-in, they might just download…), or you might want to render the document in a Display Page. For example, Videos are a good example of this need - you probably want your user to be able to play the video in situ, and don’t want them to be able to (or be forced to) download.
Anyway, I think you have two options:
Create a Display Page Template for Documents.
Use (as you’ve proposed) separate Collections for different Asset Types.
Thanks for your quick response, Ben! I’ll try to see if I can make progress with a display page template for PDF. However, I’ve already noticed that JavaScript code, for example, isn’t executed correctly in display page templates. But maybe I’ll find a good solution.
I usually deal with these kinds of issues by coding the intended behavior in Freemarker. In the collection, each item should receive INFO_ITEM_REFERENCE request parameter, which stores the className and classPK of the target object. Having that, you could implement your own logic for resolving URLs.