This page last changed on May 14, 2006 by tom@atlassian.com.
Attachments Macro
Usage: |
{attachments:patterns=pattern, ...|old=true/false|sortBy=name/size/date|upload=true/false} the patterns, old and sortBy arguments are alll optional |
Description: |
Show a list of attachments belonging to the current page.
Optionally filter attachments by name, optionally include old attachments, optionally allow uploads of new attachments. |
Example: |
|
Input: |
patterns An optional comma separated list of regular expressions, any of which must match a complete file name for it to included in the output of the macro. Note that the patterns are regular expressions, so to match a file suffix of 'jpg', use .*jpg, not *.jpg. old An optional true/false value which determines whether to show old versions of attachments. False by default. |
Output: |
A list of attachments belonging to the current page. |
Bundled with Confluence?: |
Yes |
Here's a detailed tutorial on regular expressions, but often you just need to know that '.' matches any character and '' matches zero or more occurences of the preceding character. So '.' in a regular expression matches anything (including nothing).
The regular expression pattern 'a.jpg' will match 'a123.jpg', 'axxxxxxxxjpg' or 'ajpg'. The regular expression '.*handout.' would match 'Biology handout number one.doc', 'Chemistry handout2.txt' or 'handout'.
I have a problem with regular expressions using '|' to separate alternatives, e. g.:
Error formatting macro: attachments: java.util.regex.PatternSyntaxException: Unclosed group near index 9
(Template
^
will fail as the '|' is parsed as argument separator. Of course in this case the workaround would be to use
Error formatting macro: attachments: java.lang.IllegalStateException: Attachments can not be created inside class com.atlassian.confluence.pages.Comment
but I would like to know if there is any chance to allow special characters like Unknown macro: {, | and } (and perhaps even ':') inside a pattern. I don't see any chance to escape it.

Posted by thragor@gmx.net at Sep 09, 2005 01:23
|
For the kind of patterns you're likely to need to discriminate attachments, the full regex syntax is overkill. You can supply multiple patterns, so the following will work fine:
patterns=Template.*,Vorlage.*

Posted by cmiller at Sep 09, 2005 01:31
|
My colleagues and I are also interested in hearing about true escaping, as specifying multiple patterns only works when you want to work in positives.
We specifically want to avoid particular document types in the attachments macro. If you do multiple negative lookups, you'll end up with everything anyway. So we truly need the pipe operator to work.
Also, we need the negative lookup to work, but that's a separate issue... 

Posted by anthony.atkins@vt.edu at Oct 20, 2005 10:17
|
In it's simplest form the attachments macro may be used by just including the text: in any Confluence page

Posted by noam@atlassian.com at Oct 18, 2006 23:06
|
|