getAllTags(path, [options])
Returns every distinct tag in use in a folder — the list you need to fill a tag picker, an autocomplete or a filter menu.
The values it returns are exactly the values the tag filter on listFiles and getFiles matches, because both are the normalized stored form of the tag. That is what makes the pair useful together: this function tells you what is worth filtering on, the filter then narrows to it.
Parameters
pathstringrequiredFolder path, from the site root. Pass "/" for the whole workspace. The leading slash is optional.
optionsobjectoptionalrecursiveboolInclude documents in every subfolder. Default false, which considers only the documents directly in the folder.
accessstringWhose access the list follows. Leave it out for the default: the signed-in visitor in an API script, the publisher everywhere else. 'publisher' lists with the publisher's access in an API script too — use it when your script checks permissions itself, for example looking up a record anywhere in the site and then deciding from its own user registry. It is the publisher's access, not everything: folders the publisher is denied, # folders and tool folders are still left out. Any other value throws an error.
Returns
An array of distinct tag words, lower case and sorted alphabetically. An empty array when nothing in the folder is tagged — never null.
The sorting is done for you on purpose. The list is normally rendered straight into a dropdown, and the order is meaningful to a reader. (docly.sort() needs a field name, but a plain tags.sort() works if you want another order.)
A folder that does not exist yields an empty array, not an error — the same convention as listFiles and getFiles. A mistyped path is therefore indistinguishable from an untagged folder, so check the path first when a picker comes up empty.
Throws an error if the path is empty or contains .. or a backslash.
Like getTags, this function is not restricted to the API folder. Tags from folders the user has no website (Visit) access to, and from # folders below the folder you asked for, are left out — the files they belong to are left out of listFiles and getFiles too. Access is checked for the signed-in visitor in an API script (/API/), and for the user who published the site everywhere else — on a page, and in an API script nobody is signed in to. Pass access: 'publisher' to check access for the publisher in an API script too — for an app that lets Docly handle sign-in and decides permissions itself (see Let Docly handle login, you handle the permissions). A page is cached and shared by every visitor, so on a page the list is the same for everyone.
Example
#{
/* Every tag used anywhere in the workspace */
let tags = docly.getAllTags("/", { recursive: true });
write("<select name=\"tag\">");
for (let tag of tags)
{
write("<option>" + tag + "</option>");
}
write("</select>");
}#<select name="tag"><option>2024</option><option>annual</option><option>archived</option><option>faktura</option><option>invoice</option><option>paid</option></select>