Sightly | Community
Skip to main content
Level 2
January 10, 2023
Solved

Sightly

  • January 10, 2023
  • 2 replies
  • 857 views

How to use resource path to get component path. 

/content/myproj/us/en/jcr:content/root/container/container/cloud.container.json?name="+name+"&surname="+surname

I don't want to hardcode my URL in Ajax call. How do I get the component Path and use it in my ajax. 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Sady_Rifat

You can get the Content Resource path using ${resource.path}. [/content/myproj/us/en/jcr:content/root/container/container/cloud]
If you need component resource path ${component.path}. [/apps/myproj/components/component]

In Ajax call you won't directly get those variables. You can take a hidden input in HTML and then make the path in JS.

<input type="hidden" value="${resource.path}" />

 

2 replies

Sady_Rifat
Community Advisor
Sady_RifatCommunity AdvisorAccepted solution
Community Advisor
January 10, 2023

You can get the Content Resource path using ${resource.path}. [/content/myproj/us/en/jcr:content/root/container/container/cloud]
If you need component resource path ${component.path}. [/apps/myproj/components/component]

In Ajax call you won't directly get those variables. You can take a hidden input in HTML and then make the path in JS.

<input type="hidden" value="${resource.path}" />

 

Himanshu_Singhal
Community Advisor
Community Advisor
January 10, 2023

Hi @rolliedub 
You can use .-1.json to get the JSON out of resource where resourceType property would be there (which basically is component path).
E.g. If the exact resource path is 

/content/myproj/us/en/jcr:content/root/container/container/cloud

then following url will help you obtain the resource JSON (that includes resourceType)

/content/myproj/us/en/jcr:content/root/container/container/cloud.-1.json

 I'm not sure why you're using ".container". Do you have any custom servlet in place that helps to generate JSON? If so you can use your custom ones as well.

If your component is exposed using Exporter then you can also use .model.json to get the resource JSON.

Best regards,
Himanshu Singhal