Is it possible to use the info field in a files section to show the information that a file is not used in any field (including blocks or textarea) and also filter/sort for this?
Theoretically yes, but you would have to go through all files and check if their filename exists in any of the fields or in the raw text file. I think with lots of files and content, that could potentially slow the Panel down for a feature that is probably not really important?
Then what about a hook after a file has been referenced / used in a field that adds a hidden field to the file like
Used: True
There is no such hook, you would have to use the page.update
hook and check the content if any of the files that hasn’t been used yet is now present in the content. I think that approach is better than the first. However, you never know if a file is maybe used in another page (unless this is your personal website and you never reference files anywhere else).
Okay, understood, thanks for the explanation.
As this is related I add this question here as well:
Is it possible to show the number of files of the current page in a tab label?
This doesn’t work: label: "{{ page.files.count }}"
Additionally I would like to show all files of all subpages and show in the info field the location of the file but cannot make it to work. Is it possible somehow?
sections:
allfiles:
headline: Alle Dateien ({{ page.files.count }})
type: files
layout: list
info: "{{ page.file}}"
sortBy: size desc
query: page.children.files
-
You cannot use a query with a files section. A files section can only list the files of a given page (by default the current page). Workaround: use the filesdisplay section plugin (https://github.com/texnixe/k3-filesdisplay-section)
-
page.file
returns a file object, but you would have to return a string here.
Great, that works as desired:
filetab:
icon: attachment
label: Dateien
sections:
allfiles:
headline: Alle Dateien ({{ page.children.files.count }})
type: filesdisplay
layout: list
info: "{{ file.page }} - {{ file.nicesize }}"
sortBy: size desc
query: page.children.files
Bonus question: Is it possible to show the combined nicesize of all files for that query?
3.6 has new files
methods:
- $files->size()
- $files->niceSize()