Load the book’s index node
To load the index or “home page” node from the current book, we use the loadNode method.
Why is the call wrapped in an if statement? See “Caching data” below.
URI segment or “slug”
The first parameter (“index” in this example) is the URI segment (sometimes also referred to as the “slug”) that identifies the node to be retrieved. This is the portion of the URL which can be edited by the user on the Edit screen for a page or media file.
Caching data
The second parameter is a boolean which tells scalarapi whether or not it should ignore cached data for the node. A value of “true” forces the node to be reloaded from the server, while “false,” used here, allows the cached data to be used.
The construction of the call to loadNode shown in the example accounts for cases in which cached data for the node is available. The loadNode method returns true if cached data is available for the node, and so by wrapping the call in an if statement we ensure that the success handler will be called whether the node data is cached or not.
Result handlers
The third parameter is a function to be called when the node is successfully loaded, and the fourth is a function to be called when the node fails to load.
Loading related nodes
The loadNode method can retrieve related nodes; the fifth parameter indicates how many degrees of separation will be used when searching for these. Higher numbers will increase the amount of time needed to retrieve the data; use with caution.
Previous page on path | Getting started with the Scalar API JavaScript library, page 4 of 8 | Next page on path |
Discussion of "Load the book’s index node"
Add your voice to this discussion.
Checking your signed in status ...