A simple groovy console script to find AEM pages with a certain template then display them in a nice table
copy script to AEM groovy console, change parameters and run!
copy script to AEM groovy console, change parameters and run!
/** | |
* An AEM groovy console script: https://github.com/OlsonDigital/aem-groovy-console | |
* This script finds all pages that were created using a certain template | |
*/ | |
// Change those options to serach other paths | |
def TEMPLATE = 'apps/myproject/templates/mytemplate' // the template to check for | |
def START_PATH = '/content' // the subtree to search in | |
// builds an HTML link <a> from path and title | |
def buildLink(path, title){ | |
return '<a target=\"_blank\" href=\"'+path+'\">'+ title + '</a>'; | |
//return path; | |
} | |
// builds a crx/de link <a> of path | |
def buildCrxLink(path){ | |
def newPath = "/crx/de/index.jsp#" + path; | |
return buildLink(newPath, 'Open in CRX/DE') | |
} | |
/** | |
* get list of pages that were created using templatePath | |
* @param templatePath the template path to find pages with | |
* @param startPath the path to start searching from | |
*/ | |
def getPages(templatePath, startPath){ | |
paths = []; | |
getNode(startPath).recurse{ | |
def page = getPage(it.path); | |
if(page?.template?.path?.contains(templatePath)){ | |
paths.add(page.path); | |
} | |
} | |
return paths; | |
} | |
// builds an HTML link <a> from path and title | |
def link(path, title){ | |
return "<a target=\"_blank\" href=\"${path}\">${title}</a>"; | |
//return path; | |
} | |
// builds a crx/de link <a> of path | |
def crxLink(path){ | |
def newPath = "/crx/de/index.jsp#${path}"; | |
return link(newPath, 'Open in CRX/DE') | |
} | |
// builds a touch ui editor link | |
def touchLink(path){ | |
def newPath = "/editor.html${path}" | |
return link(newPath, 'Open in Touch Editor') | |
} | |
def paths = getPages(TEMPLATE, START_PATH); // get pages with template | |
def tableRows = paths.collect { // transform paths to html <a> elements to be used as rows for table | |
def cxLink = crxLink(it) | |
def link = link(it+'.html', it) | |
def touchLink = touchLink(it) | |
return [link, cxLink, touchLink] | |
} | |
// print table | |
table { | |
columns("Page Link",'open in CRX/DE', 'Touch Editor') | |
rows(tableRows) | |
} |