Advanced Velocity Workshop #LiveFromRTC2019
Locator Tool is available only on versions 7.4 and higher. If you're not on 7.4 or higher, you're missing out!
The Locator Tool was created by the makers of Cascade CMS and is native to Cascade.
Dynamically locates assets and return Cascade API objects, not XML elements.
Locator Tool works with API objects and do not need an XML file to access data.
No XML data, so no index block is needed.
Works with API objects so it can be used on results fetched with the Query Tool.
The Locator Tool is a Velocity feature; therefore, it uses Velocity syntax. Variables and directives are syntactically the same.
Example: Setting a Variable
#set($variable = "string value")
Example: If-Else Statements
#if(conditional) // code section #elseif(conditional) // code section #end
Velocity tools are typically invoked by its name preceded by the $_ denoter. For tools that handle API objects, the denoter also contains a dot at the end. Here are some examples of the more commonly used locator tool methods:
$_.
locatePage()$_.
locateBlock()$_.
locateFolder()$_.
locateSymlink()
The locator tool can also be invoked for the following asset types: template, reference, linkable, symlink, and format.
Takes in TWO parameters to locate the asset.
$_.locatePage(PATH, SITENAME)
Takes in THREE parameters to determine which type of asset to find and where to find it.
$_.locate(PATH, TYPE, SITENAME)
#set($currPage = $_.locatePage('adv-velocity-1/_training-pages/locator-tool', 'Advanced Velocity 2019 - Master'))
The second parameter is optional. If a site name argument is not passed in, it will be defaulted to the current site.
Example:#set ($currPage = $_.locatePage('adv-velocity-1/_training-pages/locator-tool'))
This will return the same result as the above as long as the page the call from is within this site (Advanced Velocity 2019 - Master).
If this this call was made from a different site, then the site name argument should be passed in as a parameter as shown in the first example.
Variables representing a string for the path or site name can be passed in as follows:
#set($path = 'index')
#set($site = $currentPage.site.name)
#set($indexPage = $_.locatePage($path, $site))
Concatenation of Parameters is not possible. For instance, when trying to access the Web Services landing page, the following will not work.
#set($site = 'Advanced Velocity 2019 - Master')
#set($folderPath = 'adv-velocity-1/profiles')
#set($indexPath = $_.locatePage($folderPath + '/index', $site))
Instead, use the Velocity code delimiter (curly brackets) to denote the Velocity variable and be sure to use double quotes instead of single quotes.
Example:
#set($site = 'Advanced Velocity 2019 - Master')
#set($folderPath = 'adv-velocity-1/profiles')
#set($indexPath = $_.locatePage("${folderPath}/index", $site))
This will return the landing page for the Web Services section of this workshop.
$currentPage
[v7.10 +]
Returns an object.
$currentPagePath
[ v7.4+ ]
Returns a string.
$currentPageSiteName
[ v7.4+ ]
Returns a string.
Consider the examples to the right. Results shown are specific to the built-in variables being called from this page.
Example: $currentPage
com.hannonhill.cascade.api.adapters.PageAPIAdapter@241936b6
Example: $currentPagePath
adv-velocity-1/_training-pages/locator-tool
Example: $currentPageSiteName
Advanced Velocity 2019 - Master
Example: Application
Return the same results as $currentPage
$_.locatePage($currentPagePath, $currentPageSiteName)
$_.locatePage($currentPagePath)
"What is the Locator Tool?" provides a good overview that cover all the essentials.