Hi Mario,

> On 2 Feb 2017, at 19:30, Hofstätter Mario <mario.hofstaet...@automationx.com> 
> wrote:
> 
> I'd like to display a simple download button with a certain text, which 
> downloads a file attached to this xwiki page when clicked. The link has to be 
> relative to the current page (file is attached there).
> I tried the following variations of the html macro with no success. Is it 
> possible? Otherwise we will just create images for download buttons and links 
> on them.
> 
> (xwiki 8.4.3)
> 
> {{html wiki="true"}}
> <form action="">
>    <input type="submit" value="[[Download>>attach:SomeFile.png]]"/>
> </form>
> {{/html}}

This cannot work :)

The HTML macros works like this: 
http://extensions.xwiki.org/xwiki/bin/view/Extension/HTML+Macro#HParametersdefinition

"the content of the macro is parsed as markup content (written in the syntax of 
the current page) and rendered back as XHTML in the macro. Then the whole 
content is output as XHTML.”

So in your case [[Download>>attach:SomeFile.png]] will generate <a 
href=“..”>…</a>.

Thus you’ll get:

<form action="">
   <input type="submit" value="<a href=“..”>…</a>"/>
</form>

So you need to use a script such as {{velocity}}.

Here’s an example that’s similar that you should be able to adapt:
https://www.xwiki.org/xwiki/bin/view/FAQ/How+can+I+create+a+new+page+based+on+a+form

You’ll need to redirect to a download action.

$response.sendRedirect($xwiki.getURL($targetDocReference, ‘download'))

And you’ll need to compute $targetDocReference using the Model Script Service ( 
$services.model) and an attachment reference:
http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module#HScriptServiceAPI

Hope it helps
-Vincent

> 
> {{html wiki="true"}}
> <form action="[[Download>>attach:SomeFile.png]]">
>    <input type="submit" value="Download"/>
> </form>
> {{/html}}
> 
> {{html}}
> <form action="WebHome/Trendset_Dialog.png">
>    <input type="submit" value="[[Download>>attach:SomeFile.png]]"/>
> </form>
> {{/html}}
> 
> {{html wiki="true"}}
> <button type="button" onclick="[[attach:SomeFile.png]]">Download</button>
> {{/html}}
> 
> {{html}}
> <button type="button" onclick="WebHome/Trendset_Dialog.png">Download</button>
> {{/html}}
> 
> Thanks.

Reply via email to