Expand my Community achievements bar.

Sling Model with custom selector

Avatar

Level 3

Hi Team,

 

How it be possible to run sling model with custom selector without appending jcr:content in the url ?

 

similar issue : https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/register-sling-model-expor...

 

http://localhost:4502/content/tmt/en/test-pages/_jcr_content.nt.content.tidy.json

 

Thanks 

6 Replies

Avatar

Community Advisor

Hi, 

 

I assume you are talking about the Sling model exporter, if so, yes, you can actually configure the extension and selector(s)

@Model(adaptables = Resource.class, resourceType="/apps/myApps/components/myComponent", defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)

@Exporter(name = "jackson", selector="mySelector", extensions = "myextension", options = { @ExporterOption(name = "SerializationFeature.WRITE_DATES_AS_TIMESTAMPS", value = "true") })

 Here you can find a detailed article explaining how to use the Sling Model Exporter using custom selectors http://sgaem.blogspot.com/2017/06/sling-model-exporter-in-aem-63.html 

 

If, on the other hand, you are trying to access something like this: http://localhost:4502/content/tmt/en/test-pages/_jcr_content.nt.content.tidy.json without "jcr:content" in the path, you could set up a redirect. However, the full path is most likely correct because it clearly indicates the source of the "json" data.

 

Hope this helps.



Esteban Bustamante

Thank you!

 

Similar approach I have followed but <resoucePath>.model.json works why not <resourcePath>.custom.test.json works.

Do you know why I need to write the redirect?

 

Avatar

Level 5

I assume it's ootb behavior that handles model.json resolution for pages in that manner so we can avoid appending jcr content . One option I can think of is writing a sling filter to forward the request to /jcr:content.custom.json when selector is custom and incoming path is indeed a cqpage. But again the question is where is it that you want this custom selector? If it's spa use local Dev model client to append the path instead of implementing a backend solution. Hope this info helps. 

Avatar

Level 3

Hi @mahi1729 

 

I have to expose pageContent via custom SlingModel to external App . This will not be used by any component on the page.

 

Thanks

Avatar

Administrator

@Sumit30908642ioye  Do you find the suggestions from users useful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni

Avatar

Level 1

Hello

To run a Sling Model with a custom selector without appending "jcr:content" to the URL https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/register-sling-model-expor...Salesforce Marketing Cloud Course in AEM, follow these steps:

  1. Create a Sling Model with the correct resource type.
  2. Configure the resource type in AEM.
  3. Use the custom selector in the URL, like yourpage.customselector.json.
  4. Handle the selector logic in your Sling Model.

This allows you to access the desired content without "jcr:content" in the URL.

 

Thank you.