Accessing to Objects custom fields in an Aplication Diplay Template

Issue

  • I'm configuring a search results ADT for a custom Object. By default I can choose, in the available variables, the title, author, etc. But I need to access custom fields of the Object as well.

Environment

  • Liferay DXP 7.4

Resolution

  • Search for the service endpoint in the API console ( /o/api ) on a web browser corresponding to the Object entity.
  • In the ADT make a call to the rest service using the "restClient" and the classPK as Id.
<#if entries?has_content>
<#list entries as entry>
<#assign myobject = restClient.get("/c/myobjects/${entry.getClassPK()}")>
field1: ${myobject.field1} <br>
field2: ${myobject.field2} <br>
field3: ${myobject.field3} <br>
</#list>
</#if>

 

Additional Information

  • Here is a recorded session with a live demo by Alejandro Tardín that explain perfectly how to implement this solution:

https://liferay.dev/twentyfour#Put%20your%20templates%20at%20REST

 

 

这篇文章有帮助吗?
1 人中有 0 人觉得有帮助