I have created a component the fields of which have been mapped to a sling model. To get the data of the sling as JSON I have enabled Sling exporter as shown in the code below -
@Model(adaptables = { Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL, resourceType = "XXX/components/content/XXX")
@Exporter(name = "jackson", extensions = "json")
public interface ProofPointsModel {
@Inject
List<ProofPointsList> getProofPoint();
@Model(adaptables = { Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
interface ProofPointsList {
@Inject
String getProofText();
@Inject
String getProofIcon();
}
}
This works perfectly and I am able to see the JSON data when hit the end point from my browser. I want to render this entire json object in my component's HTL. Is there an elegant way of doing this? I dont want to create an additional request to retrieve this data. Basically I want to call this sling exporter from within my component and render the json object as is.
Thanks
Unfortunately, HTL does not allow doing these "server-side includes". The workaround is to expose the JSON in a getJson
method of your model: Get.model.json as String
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.