Expand my Community achievements bar.

SOLVED

Sightly

Avatar

Level 2

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. 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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}" />

 

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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}" />

 

Avatar

Community Advisor

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