GraphQL requests to resolve links
Content Delivery can resolve links dynamically; that is, if a Content Manager user creates a link to a Component, and if that Component (rendered as a Component Presentation) occurs on multiple webpages on your published website, Content Delivery can resolve the link by pointing to a specific page, based on its own internal logic and on your own custom configuration about how to resolve links. Samples show you how to involve this link-resolving logic.
In all requests that follow, the namespaceId property is always set to 1, indicating Tridion Sites, and publicationId is always set to the unique identifier of the Content Manager Publication that corresponds to the current website.
Also, all requests below return a relative link. To get a fully qualified URL instead (as per your Dynamic Linking configuration and the Linking API), add the following parameter-value pair to the list of the pageLink, componentLink or binaryLink parameters: renderRelativeLink: false.
{
pageLink(namespaceId: 1, publicationId: 23, pageId: 264) {
url
itemId
type
}
}
where pageId is set to the identifier of the Page that corresponds with the current webpage, which contains the link.
{
componentLink(namespaceId: 1, publicationId: 11, sourcePageId: 92, targetComponentId: 757, excludeComponentTemplateId: 4521) {
url
itemId
type
}
}
sourcePageIdis the identifier of the Page that corresponds with the current webpage, which contains the link.targetComponentIdis the identifier of the Component that the link points to in Content Manager. On the website, the link will point to a webpage that contains the same Component, rendered with some Component Template.- (optional)
excludeComponentTemplateIdis the identifier of a Component Template. Use this parameter in scenarios where a Component may be linking to itself. Typically, a Component links to itself in order to make a "small" rendering of the Component (say, showing only a title) to a "big" rendering (showing all Component fields). A special case of a Component linking to itself is when not only the source and target Component are the same, but also the source and target Component Presentation. In this situation, two different webpages contain the exact same Component Presentation, that is, the same Component rendered with the same Component Template. In this situation, both Component Presentations could end up pointing to each other; that is, to exact copies of themselves, but on another webpage. Most likely, you do not want this to happen. You can prevent this by explicitly excluding the Component Template with which the source Component has been rendered; that is, by settingexcludeComponentTemplateIdto the ID of that Component Template.
{
dynamicComponentLink(namespaceId: 1, publicationId: 8, targetPageId: 723, targetComponentId: 116, targetTemplateId: 646) {
url
itemId
type
}
}
targetPageIdis the identifier of the Page that contains the dynamic Component Presentation that resulted from rendering the target Component with a dynamic Component Template.targetComponentIdis the identifier of the Component that the link points to in Content Manager. On the website, the link will point to a webpage that contains the same Component, rendered with some dynamic Component Template.targetTemplateIdis the identifier of a Component Template that the target Component was rendered with.
{
binaryLink(namespaceId: 1, publicationId: 4, binaryId: 760) {
url
itemId
type
}
}
where binaryId is the identifier of the Multimedia Component that corresponds with the current webpage, which contains the link.