Get node ancestors
Log in to add to favouritesCall the nodes.getAncestors() method in our delivery client to get the ancestor nodes of an existing node from site view, optionally resolving an attached entry
Call signatures
getAncestors(id: string): Promise<Node[]>
getAncestors(node: Node): Promise<Node[]>
getAncestors(options: NodeGetAncestorsOptions): Promise<Node[]>
Parameters
Name | Type | Description |
---|---|---|
id | string | The id of the node |
node | Node | A node object |
options | NodeGetAncestorsOptions | An options object to apply additional refinements |
Returns
A Promise that will resolve an array of Node
Remarks
If a start level is specified that is equal to or greater than the level of the start node then an empty array will be returned
Throws any error that is returned by the API for any other unsuccessful request echoing the HTTP status returned from the API
Examples
Get all ancestor nodes of an existing node
const nodes = await client.nodes.getAncestors(
"7a301bf2-96c3-461c-8068-bebe6783ecc5"
);
for (const node of nodes) {
console.log(node.path);
}
Get all ancestor nodes of an existing node starting at level 2 also resolving the entryTitle field of any entry attached to the returned nodes
const nodes = await client.nodes.getAncestors({
id: "7a301bf2-96c3-461c-8068-bebe6783ecc5",
startLevel: 2,
entryFields: ["entryTitle"],
});
for (const node of nodes) {
console.log(`${node.path} ${node.entry?.entryTitle || ""}`);
}
Get node ancestor at level
Call the nodes.getAncestorAtLevel() method in our delivery client to get the ancestor node of an existing node at a specific level from site view, optionally resolving an attached entry
Call signatures
getAncestorAtLevel(options: NodeGetAncestorAtLevelOptions): Promise<Node>
Parameters
Name | Type | Description |
---|---|---|
options | NodeGetAncestorAtLevelOptions | An options object to supply required refinements |
Returns
A Promise that will resolve with a Node
Remarks
If a level is specified that is equal to or greater than the level of the start node then null will be returned
Throws any error that is returned by the API for any other unsuccessful request echoing the HTTP status returned from the API
Example
Get the ancestor nodes of an existing node at level 2 also resolving the entryTitle field of any entry attached to the returned node
const node = await client.nodes.getAncestorAtLevel({
id: "7a301bf2-96c3-461c-8068-bebe6783ecc5",
startLevel: 2,
entryFields: ["entryTitle"],
});
Get node parent
Call the nodes.getParent() method in our delivery client to get the immediate ancestor node of an existing node from site view, optionally resolving an attached entry
Call signatures
getParent(id: string): Promise<Node>
getParent(node: Node): Promise<Node>
getParent(options: NodeGetParentOptions): Promise<Node>
Parameters
Name | Type | Description |
---|---|---|
id | string | The id of the node |
node | Node | A node object |
options | NodeGetParentOptions | An options object to apply additional refinements |
Returns
A Promise that will resolve with a Node
Remarks
Throws any error that is returned by the API for any unsuccessful request echoing the HTTP status returned from the API
Examples
Get the parent node of an existing child node by the child node's ID
const node = await client.nodes.getParent(
"7a301bf2-96c3-461c-8068-bebe6783ecc5"
);
console.log(node.path);
Get the parent node of an existing child node by the child node's ID supplying specific options
const node = await client.nodes.getParent({
id: "7a301bf2-96c3-461c-8068-bebe6783ecc5",
language: "en-GB",
entryFields: ["entryTitle"],
});
console.log(`${node.path} ${node.entry?.entryTitle || ""}`);