Hi All,
How can I use Externalizer in JavaScript Use API, I can easily use it using Java API. But I need this in JavaScript Use API to add canonical tag in head section of pages for SEO purpose.
-Thanks,
Raghava
Solved! Go to Solution.
Views
Replies
Total Likes
Hi, Raghava.
You can use the sling global object (it is an instance of the SlingScriptHelper class) to obtain a reference to the Externalizer service.
Untested code:
var externalizer = sling.getService(Packages.com.day.cq.commons.Externalizer); var externalURL = externalizer.externalLink(resolver, resource.getPath());
Regards,
Daniel.
Views
Replies
Total Likes
Hi, Raghava.
You can use the sling global object (it is an instance of the SlingScriptHelper class) to obtain a reference to the Externalizer service.
Untested code:
var externalizer = sling.getService(Packages.com.day.cq.commons.Externalizer); var externalURL = externalizer.externalLink(resolver, resource.getPath());
Regards,
Daniel.
Views
Replies
Total Likes
Hi Daniel,
Thanks for the inputs, I'll try implementing this.
Views
Replies
Total Likes
Hi, Raghava
Here is the example with CQ JS API - CQ.HTTP.externalize. You may try something like this.
var currentPageContent = CQ.HTTP.get(CQ.HTTP.externalize(CQ.utils.WCM.getPagePath() + "/jcr:content.json"));
Thanks!
Views
Replies
Total Likes
Vamsi, AFAIK CQ.HTTP is exposed by a client lib and therefore is not available to be used in a JavaScript Use (a server side element interpreted by Rhino).
Regards,
Daniel.
Views
Replies
Total Likes
Thanks Daniel it worked,
Working code snip:
var externalizer = sling.getService(Packages.com.day.cq.commons.Externalizer);
var externalURL = externalizer.externalLink(global.resource.getResourceResolver(),"publish", global.currentPage.getPath());
Thanks.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies