I am looking for the API call that will allow me to get a list of all documents and their aliases using a certain template to create a list of links from.
All input is appreciated.
Tabor Carlton
Thanks for this, Tabor.
How would I go about using that code? Would I just save it as a snippet, and then make a page which calls that snippet?
I want to find out which pages use which template, as we have ended up with a number of interim and development templates on our site as we have progressed, and it’s now time for a tidy-up to get rid of unused templates and replace little-used templates with others, where possible. However, there doesn’t seem to be anything in the MODx Manager which shows this information (or I’ve not found it, if there is), so this code might be of use to me.
Please don't PM me unless it's absolutely essential: if a technical question is worth asking, it's worth asking in public, so that others can share their experience, and so that all can learn from the answers.
Yes, throw that code into a snippet (PHP must be run in snippets) and then you can just call that snippet in the [*content*] variable - don’t even worry about going into code view or anything... just dump it straight into the rich text area for your [*content*] variable.
Try this in your snippet call David:
<?php
// get list all documents in site
$list = $modx->documentListing;
// convert to numerical array
// * this is required, there are no numeric indexes available
$list = array_values($list);
// loop through all documents
for ($i=0; $i<sizeof($list); $i++) {
// get information about each page based on document Id ($list[$i])
$array = $modx->getPageInfo($list[$i],1,'template');
print 'This document uses template: ' . $array['template'];
}
?>
Hope that answers your question.
Tabor