Builders

Additional binding variables are provided for the following builders. The instances named below are available for use in all scripts. Builders use a special syntax to create a structured tree of data (in this case, content in the JCR).

  • nodeBuilder - Each "node" in the syntax tree corresponds to a Node in the repository. A new Node is created only if there is no existing node for the current name.
    nodeBuilder.etc {
        satirists("sling:Folder") {
            bierce(firstName: "Ambrose", lastName: "Bierce", birthDate: Calendar.instance.updated(year: 1842, month: 5, date: 24))
            mencken(firstName: "H.L.", lastName: "Mencken", birthDate: Calendar.instance.updated(year: 1880, month: 8, date: 12))
            other("sling:Folder", "jcr:title": "Other")
        }
    }
    • A single string argument represents the node type name for the node ("satirists").
    • A map argument uses the provided key:value pairs to set property values on the node ("bierce" and "mencken").
    • Both string and map arguments will set the node type and property value(s) for the node ("other").
  • pageBuilder - Each "node" in the syntax tree corresponds to a cq:Page node, unless the node is a descendant of a "jcr:content" node, in which case nodes are treated in the same manner as described for the Node builder above.
    pageBuilder.content {
        beer {
            styles("Styles") {
                "jcr:content"("jcr:lastModifiedBy": "me", "jcr:lastModified": Calendar.instance) {
                    data("sling:Folder")
                }
                dubbel("Dubbel")
                tripel("Tripel")
                saison("Saison")
            }
            breweries("Breweries", "jcr:lastModifiedBy": "me", "jcr:lastModified": Calendar.instance)
        }
    }
    • A single string argument is used to set the page title rather than the node type ("styles").
    • Descendants of "jcr:content" nodes are not created with the cq:Page type by default and can have their own node type specified as described for the Node builder ("data").
    • Page properties can be passed directly as arguments on the page node without explicitly creating a jcr:content node first ("breweries").