Access AEM component data as JSON within HTL (Sightly)

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

1 answer

  • answered 2021-05-31 12:06 Vlad

    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

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum