Gallery macro / velocity question: referring to filenames with spaces

With reference to the macro/velocity script specified on this page:

Specifically,

{{velocity}}
#set ($attachments = $doc.attachmentList)
#if ($attachments.size() > 0)
  {{gallery}}
    #foreach($attachment in $attachments)
      #if($attachment.isImage())
        image:$attachment.filename
      #end
  #end
  {{/gallery}}
#end
{{/velocity}}

If the attached image file names have spaces in them, this script does not work as it cannot load the files. How can this script be modified to accept attachment file names with spaces? For example, is it possible to urlencode the string $attachment.filename? Is there a different syntax that can be used for image:?

update: I am messing around with the manually specifying the image names, ala:

{{gallery}}

image:halloween%20-%201.jpg

image:halloween - 2.jpg

{{/gallery}}

In the first instance, the site tries to load halloween%2520-%25201.jpg – in other words, it double-encodes the filename. In the second instance, xwiki tries to load halloween – it doesn’t understand spaces.

That means my idea of urlencoding, above, is not a solution. Is there any way to specify attachments with spaces to image:? A look at the Xwiki Syntax 2 document does not indicate any method of so doing, all examples are spaceless filenames. http://platform.xwiki.org/xwiki/bin/view/XWiki/XWikiSyntax?syntax=2.0

Thanks.

D’oh. Figured it out. using [[ ]] allows the use of spaces, which is not spelled out in the syntax document but is inferrable. So the modified, functioning, script looks like this:

{{velocity}}
#set ($attachments = $doc.attachmentList)
#if ($attachments.size() > 0)
  {{gallery}}
    #foreach($attachment in $attachments)
      #if($attachment.isImage())
        [[image:$attachment.filename]]
      #end
  #end
  {{/gallery}}
#end
{{/velocity}}

Cool, I love it when someone asks a question and posts the answer! :slight_smile: Thanks.

I’ve now edited the example on http://extensions.xwiki.org/xwiki/bin/view/Extension/Gallery%20Macro

BTW don’t hesitate to edit wiki pages on xwiki.org to improve them or fix problems or add explanations!

Thanks @vmassol! Normally I have no problem editing wiki pages but in this case, just wanted to wait for confirmation that I wasn’t missing something. It may be worth editing the syntax guide as well to have examples with spaces.

Would you mind creating a PR in Github for it? :slight_smile: The page that contains the content is stored here: xwiki-platform/xwiki-platform-core/xwiki-platform-help/xwiki-platform-help-ui/src/main/resources/XWiki/XWikiSyntaxImages.xml at c98cf088c798d8c68c59734a5a25723f5c75c98b · xwiki/xwiki-platform · GitHub

Thx!