{filelink:url:fname:text_before}

Description

Builds an HTML download link for a file URL, annotated with the file type and size. Returns an a-element whose href and link text come from the URL (or from a supplied label), with a title attribute and a trailing fileinfo span showing the type and size in brackets. An empty url returns an empty string. Internally it asks fileinfo for the type (the URL extension) and size (read from the local upload path, or fetched over HTTP); the size is empty when the file is neither a local upload nor reachable, so only the type shows. Use it to turn a stored file field into a ready-made download link.

Parameters

url required default (empty string)

URL of the file to link to. With a leading slash it is treated as a path on the current host. An empty url makes the whole expression return an empty string.

fname optional default basename of the URL path

Link text and title label for the file. When omitted, the basename of the URL path is used (for example report.pdf).

text_before optional default (empty string)

Text placed immediately before the link, for example a Download#: prefix. It is not trimmed, so a trailing space is kept. Escape a literal colon as #: so it is not read as a parameter separator.

Examples

virtual{filelink:https://example.org/files/report.pdf}
Expectedreport.pdf [pdf - ]
report.pdf [pdf - ]">Actualreport.pdf  [pdf - ]
With only the url, the link text and title come from the basename of the path (report.pdf) and the type/size badge is appended. The size is empty here because the file is not a local upload and the host is not reachable, so only the type pdf shows. Marked illustrative because the output is HTML and the size depends on the runtime environment.
virtual{filelink:https://example.org/files/report.pdf:Annual report}
ExpectedAnnual report [pdf - ]
Annual report [pdf - ]">ActualAnnual report  [pdf - ]
The second parameter sets the link text and the title label, overriding the basename. Here the link reads Annual report instead of report.pdf. Illustrative: HTML output, runtime-dependent size.
test[{filelink:}]
Expected[]
Actual[]
When the url is empty the whole expression returns an empty string, so nothing is rendered. The brackets here just show that the output between them is empty.
virtual{filelink:https://example.org/files/report.pdf:Annual report:Download#: }
ExpectedDownload: Annual report [pdf - ]
Annual report [pdf - ]">ActualDownload: Annual report  [pdf - ]
The third parameter is placed right before the link. A literal colon must be escaped as #: so it is not read as a parameter separator. text_before is not trimmed, so the trailing space after Download: is kept. Illustrative: HTML output, runtime-dependent size.
virtual{filelink:{file............}:{text............}:Download#: }
ExpectedDownload: Report [pdf - 157 kB]
The canonical usage: the url comes from a stored file field and the label from a text field of the same item. With a real uploaded file the size resolves (for example 157 kB). Illustrative because it depends on item field values and the actual file.