1

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.

1 Answers1

1

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);
%>
AdrianRM
  • 2,622
  • 2
  • 25
  • 42
  • The snippet is not useful because I need to process the data in java first (between <% %>) So I need something from Java doc, but the thing is that I don't have the path to the xml (content). Every time a piece of content gets rendered via a formatter I need to get the value from a field of the content and process it and then output it eg: <% String valueFromField = getValueFromContentViaFormatter(); //process valueFromField out.println(valueFromField); %> – mihailacusteanu Mar 08 '17 at 19:22