Generate a Site Details Page URL with an API
If you're rendering a list of content items in a content layout from your own query, you can create a link to a detail page for a content item. You can use the Sites SDK SCSRenderAPI.getPageLinkData
API to generate a Site Details page URL.
The detailPageId
property is the ID of the detail page selected in the content item or the content list. If the value wasn't set, the value returned is the first page in the SiteStructureMap
that has the isDetailPage
property set.
To access this property, you can use the Sites SDK. This is available only when the content layout is used for an Oracle Content Management site. It can be accessed only through scsData, which is passed as one of the arguments when the content layout is created. For example:
scsData.SitesSDK.getProperty('detailPageId', function (detailPageId) { console.log(detailPageId);});
Once you have the detailPageId
, you can use it to construct the link to the detail page.
The SCSRenderAPI has a function, getPageLinkData()
, that takes in a pageId
and additional options and constructs the required URL to the page passing through the options. The signature for this function follows:
SCSRenderAPI.getPageLinkData(pageId,
options);
It has the following parameters:
-
pageId: The same as the
detailPageId
returned from the Sites SDKdetailPageId
property. -
options:
-
contentType
-
contentId
-
contentName
-
The return value is an object with these properties:
-
hideInNavigation
-
href
-
href
The next example puts this all together:
scsData.SitesSDK.getProperty('detailPageId', function (detailPageId) {
var pageDetails = SCSRenderAPI.getPageLinkData(pageId, {
'contentType': contentType,
'contentId': contentId,
'contentName': contentItemData.slug || contentItemData.name
});
// get the URL to the page
console.log(pageDetails.href);
});
This would print out as: "/sites/{site}/{detailPageName}/{contentType}/{contentId}/{contentSlug}
"
If the pageId
is not a detail page, then the content values are not added to the URL.
See the Oracle Content Management SDKs.