I’m trying to create a Macro which opens a URL (a website) on a new tab in the browser.
I can’t get the link to work…it’s not parsing it correctly.
The “link” parameter is like “http://www.google.com ” (without the quotes).
Can somebody help me out?
Here’s my code
{{velocity}}
#set($titel=$xcontext.macro.params.Titel)
#set($omschrijving=$xcontext.macro.params.Omschrijving)
#set($icon=$xcontext.macro.params.Icon)
#set($link=$xcontext.macro.params.Link)
{{html wiki="true"}}
<a href=$link target="_blank">
<div style="
width: 240px;
height: 240px;
display: inline-block;
padding-left: 5px;
background-color: rgb(255,255,255);
border-radius: 2px;
border-width: 2px;
border-style: solid;
text-align: center;
cursor: pointer;
">
<br>
{{icon name=$icon size="4x" title=$titel}}{{/icon}}<br>
<br>
**$titel**<br>
<br>
//$omschrijving//<br>
<br>
</div>
<br>
</a>
{{/html}}
{{/velocity}}
vmassol
October 29, 2018, 10:42am
2
I’d suggest to use a SPAN inside a A, since DIV is for block level.
Also you should use href="$link"
.
vmassol
October 29, 2018, 10:42am
3
Note that you don’t need HTML btw, you can write this in wiki syntax too if you want.
I have tried using href="$link", but then the “//” in the URL are messing it all up.
Do I need to encode/decode the URL?
I like the HTML for the formatting
vmassol
October 29, 2018, 10:53am
5
So your issue is that you’re saying wiki=true
so the content is parsed as wiki content and //
means italic in xwiki syntax… You need to escape it with ~/~/
.
vmassol
October 29, 2018, 10:54am
6
There’s an escape API for wiki syntax to help you
vmassol
October 29, 2018, 10:58am
7
Example:
{{velocity}}
{{{$services.rendering.escape("http://...", 'xwiki/2.1')}}}
{{/velocity}}
vmassol
October 29, 2018, 10:59am
8
Otherwise just don’t use the HTML macro as I suggested
Guess I should have mentioned that we are still at XWiki 5.4.3
When was the escape API introduced in XWiki?
On the bright side, if I escape the “/” by hand, it all works fine
vmassol
October 29, 2018, 12:16pm
10
I feel your pain! Note that we don’t support old versions of XWiki: https://www.xwiki.org/xwiki/bin/view/Main/Support#HSupportedVersions
When do you plan to upgrade to XWiki 10.8.1+?
You should really try to keep up with XWiki releases (at least following the LTS, that’s once per year). It makes life easier.