Skip to main content

Call the nodes.getSiblings() method in our delivery client to get the sibling nodes of an existing node from site view, optionally resolving an attached entry

Call signatures

TypeScript
getSiblings(id: string): Promise<Node[]>

getSiblings(node: Node): Promise<Node[]>

getSiblings(options: NodeGetSiblingOptions): Promise<Node[]>

Parameters

NameTypeDescription
idstringThe id of the node
nodeNodeA node object
optionsNodeGetSiblingOptionsAn options object to apply additional refinements

Returns

A Promise that will resolve an array of Node

Remarks

Returns an empty array if no sibling nodes are 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 sibling nodes of an existing node

TypeScript
const node = await client.nodes.getSiblings(
  "7a301bf2-96c3-461c-8068-bebe6783ecc5"
);

for (const node of nodes) {
  console.log(node.path);
}

Get the sibling nodes of an existing node also resolving the entryTitle field of any entry attached to the returned nodes

TypeScript
const nodes = await client.nodes.getSiblings({
  id: "7a301bf2-96c3-461c-8068-bebe6783ecc5",
  entryFields: ["entryTitle"],
});

for (const node of nodes) {
  console.log(
    node.path,
    node.childCount ? `+${node.childCount}` : "",
    node.entry?.entryTitle || ""
  );
}

Still need help?

If you still need help after reading this article, don't hesitate to reach out to the Contensis community on Slack or raise a support ticket to get help from our team.
New support request