mihailacusteanu
mihailacusteanu

Reputation: 53

How to list files from a folder in opencms?

I need to create a new resource type in opencms which have 1 field. The field is for a target folder. Every time I select a folder from VFS and save the resource(xml) the formatter will render a the list of files from the specified folder.

I managed to create a jsp file which will create the list of files needed, but only with the target folder hardcoded. I don't know how to read data from the resource type(xml), which I can access using el expression.

Upvotes: 1

Views: 1020

Answers (1)

AdrianRM
AdrianRM

Reputation: 2771

I am not sure if this works. Please try it out.

<cms:formatter var="content" val="value">
    <cms:contentload collector="singleFile" param="${value.TargetFolder.stringValue}">
        <cms:contentshow element="Title" />
    </cms:contentload>
</cms:formatter>

value is of type Map<String, CmsJspContentAccessValueWrapper>. You can check the Javadoc to see which other methods you have available.

I took the collector from: CmsDefaultResourceCollector.getSingleFile()

Another way to read XMLContent is with Java. e.g.:

<c:set var="path" value="${value.TargetFolder.stringValue}"/>
<%
  String path = pageContext.getAttribute("path");
  CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(jsp.getCmsObject(), path);
  xmlContent.getStringValue(jsp.getCmsObject(), "Title", locale);
%>

Upvotes: 1

Related Questions