• Document Up to Date

Get Pages for a Given Site

In this example we create a simple RESTful service that returns the list of Pages in a site. The service is parameterized to allow the caller to set a starting point and depth.

Prerequisites

  • None

Step 1: Create a REST Controller

  • Under Scripts/rest right click and click create controller
    • Enter get-pages.get as the controller name

  • Add the following code to the controller.

 1def pathParam = (params.path != null) ? params.path : ""
 2def depthParam = (params.depth != null) ? params.depth.toInteger() : 0
 3
 4def path = "/site/website" + pathParam
 5def depth = depthParam != 0 ? depthParam : 2
 6
 7def navItems = [:]
 8def siteDir = siteItemService.getSiteTree(path, depth)
 9
10if(siteDir) {
11    def dirs = siteDir.childItems
12    dirs.each { dir ->
13            def dirName = dir.getStoreName()
14            def dirItem = siteItemService.getSiteItem("/site/website/${dirName}/index.xml")
15
16            if (dirItem != null) {
17                def dirDisplayName = dirItem.queryValue('internal-name')
18
19                navItems.put(dirName, dirDisplayName)
20            }
21   }
22}
23
24return navItems

Step 2: Execute the Service