HTML Macro - Create a link

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 “” (without the quotes).

Can somebody help me out?

Here’s my code


{{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;
{{icon name=$icon size="4x" title=$titel}}{{/icon}}<br>

I’d suggest to use a SPAN inside a A, since DIV is for block level.

Also you should use href="$link".

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 :slight_smile:

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 ~/~/.

There’s an escape API for wiki syntax to help you


{{{$services.rendering.escape("http://...", 'xwiki/2.1')}}}

Otherwise just don’t use the HTML macro as I suggested :wink:

Guess I should have mentioned that we are still at XWiki 5.4.3 :tired_face:
When was the escape API introduced in XWiki?

On the bright side, if I escape the “/” by hand, it all works fine :smiley:

I feel your pain! :slight_smile: Note that we don’t support old versions of XWiki:

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.