[opencms-dev] JSON output

Диканский Андрей Юрьевич adikanskii at ncfu.ru
Tue Feb 12 17:37:00 CET 2019


I've modified my code with for each loop.


<cms:contentload collector="allInFolder" param="/service/1/Direction-%(number).xml|Direction" preload="true">
  <cms:contentinfo var="info" />
  <c:if test="${info.resultSize > 0}">
  Results<br>
  <cms:contentload>
     <cms:contentaccess var="content" />
  <c:forEach var="teaser" items="${content.valueList['Title']}">
      <cms:jsonpart element="Title">  ${teaser}  </cms:jsonpart><br>
     </c:forEach>
   </cms:contentload>
  </c:if>
 </cms:contentload>

In /service/1/ I have 3 files: Direction1.xml, Direction2.xml, Direction3.xml


But in JSON output I have content of the last item of the loop only:

{"parts":["Title","Title","Title"],"Title":"Title 1"}

?I expect to see in JSON output something like this:

{"parts":["Title","Title","Title"],
"Title":"Title 1",
"Title":"Title 2",
"Title":"Title 3"}

Can I achive it in OpenCMS with jsonpart? tag?


Andrew Dikansky

________________________________
От: Диканский Андрей Юрьевич
Отправлено: 7 февраля 2019 г. 10:29
Кому: opencms-dev at opencms.org
Тема: JSON output


Hello

I'm trying to use <cms:jsonpart> tag to provide  convertations parts of my HTML to JSON.

I edited a formatter for the default resource type by adding <cms:jsonpart>.

<cms:formatter var="content">
<div class="margin-bottom-30">
<div class="headline">
<cms:jsonpart element="title"><h3 ${content.rdfa.Title}>${content.value.Title}</h3></cms:jsonpart>
</div>
<div class="row">
<c:if test="${content.value.Image.exists}">
<div class="col-md-4 col-sm-2 hidden-xs">
<div class="thumbnail-kenburn">
<div class="overflow-hidden">
<cms:img src="${content.value.Image}" scaleColor="transparent"
width="400" scaleType="0" noDim="true" cssclass="img-responsive" />
</div>
</div>
</div>
</c:if>
<div class="${content.value.Image.exists ? 'col-md-8 col-sm-10 col-xs-12' : 'col-xs-12' }">
<div ${content.rdfa.Text}><cms:jsonpart element="description">${content.value.Text}</cms:jsonpart></div>
<c:if test="${content.value.Link.exists}">
<p>
<a class="btn-u btn-u-small"
href="<cms:link>${content.value.Link}</cms:link>">${paragraph.value.Link}</a>
</p>
</c:if>
</div>
</div>
</div>
</cms:formatter>


The problem is that I have several content elements  of this formater on one page, so json output contains only the last one element content.
What should I change in my jsp to provide all content of all elements to json output? Where should I make it? In template main.jsp?

Andrew Dikansky

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20190212/b620e699/attachment.htm>


More information about the opencms-dev mailing list