Get the root node
Log in to add to favouritesCall the nodes.getRoot() method in our delivery client to return the root node from the project site view tree
Call signatures
getRoot(options?: NodeGetRootOptions): Promise<Node>
Parameters
Name | Type | Description |
---|---|---|
options | NodeGetRootOptions | An options object to apply additional refinements |
Returns
A Promise that will resolve with the root Node
Remarks
Throws any error that is returned by the API for any unsuccessful request echoing the HTTP status returned from the API
Example
Get the root node with default options
const node = await client.nodes.getRoot();
console.log(node);
Get root node for a specific language while resolving children to a depth of 1 and the entry title field from any entry attached to any resolved node
const node = await client.nodes.getRoot({
depth: 1,
language: "en-GB",
entryFields: ["entryTitle"],
});
for (const child of node.children) {
console.log(
child.path,
child.childCount ? `+${child.childCount}` : "",
child.entry?.entryTitle || ""
);
}