# HTML Macro - Create a link

**URL:** <https://forum.xwiki.org/t/html-macro-create-a-link/3826>\
**Category:** Help / Discuss\
**Tags:** link, html5\
**Created:** [October 29, 2018, 10:40am UTC](https://forum.xwiki.org/t/html-macro-create-a-link/3826 "2018-10-29T10:40:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![HamsterNL](https://forum.xwiki.org/user_avatar/forum.xwiki.org/hamsternl/32/19_2.png) [@HamsterNL](https://forum.xwiki.org/u/HamsterNL)\
**Post date:** [October 29, 2018, 10:40am UTC](https://forum.xwiki.org/t/html-macro-create-a-link/3826/1 "2018-10-29T10:40:01Z")

</div>

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](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}}

```

---

<div class="post-metadata">

**Author:** ![vmassol](https://forum.xwiki.org/user_avatar/forum.xwiki.org/vmassol/32/6_2.png) [@vmassol](https://forum.xwiki.org/u/vmassol)\
**Post date:** [October 29, 2018, 10:42am UTC](https://forum.xwiki.org/t/html-macro-create-a-link/3826/2 "2018-10-29T10:42:28Z")

</div>

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

Also you should use `href="$link"`.

---

<div class="post-metadata">

**Author:** ![vmassol](https://forum.xwiki.org/user_avatar/forum.xwiki.org/vmassol/32/6_2.png) [@vmassol](https://forum.xwiki.org/u/vmassol)\
**Post date:** [October 29, 2018, 10:42am UTC](https://forum.xwiki.org/t/html-macro-create-a-link/3826/3 "2018-10-29T10:42:51Z")

</div>

Note that you don’t need HTML btw, you can write this in wiki syntax too if you want.

---

<div class="post-metadata">

**Author:** ![HamsterNL](https://forum.xwiki.org/user_avatar/forum.xwiki.org/hamsternl/32/19_2.png) [@HamsterNL](https://forum.xwiki.org/u/HamsterNL)\
**Post date:** [October 29, 2018, 10:50am UTC](https://forum.xwiki.org/t/html-macro-create-a-link/3826/4 "2018-10-29T10:50:01Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![vmassol](https://forum.xwiki.org/user_avatar/forum.xwiki.org/vmassol/32/6_2.png) [@vmassol](https://forum.xwiki.org/u/vmassol)\
**Post date:** [October 29, 2018, 10:53am UTC](https://forum.xwiki.org/t/html-macro-create-a-link/3826/5 "2018-10-29T10:53:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vmassol](https://forum.xwiki.org/user_avatar/forum.xwiki.org/vmassol/32/6_2.png) [@vmassol](https://forum.xwiki.org/u/vmassol)\
**Post date:** [October 29, 2018, 10:54am UTC](https://forum.xwiki.org/t/html-macro-create-a-link/3826/6 "2018-10-29T10:54:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vmassol](https://forum.xwiki.org/user_avatar/forum.xwiki.org/vmassol/32/6_2.png) [@vmassol](https://forum.xwiki.org/u/vmassol)\
**Post date:** [October 29, 2018, 10:58am UTC](https://forum.xwiki.org/t/html-macro-create-a-link/3826/7 "2018-10-29T10:58:53Z")

</div>

Example:

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

```

---

<div class="post-metadata">

**Author:** ![vmassol](https://forum.xwiki.org/user_avatar/forum.xwiki.org/vmassol/32/6_2.png) [@vmassol](https://forum.xwiki.org/u/vmassol)\
**Post date:** [October 29, 2018, 10:59am UTC](https://forum.xwiki.org/t/html-macro-create-a-link/3826/8 "2018-10-29T10:59:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HamsterNL](https://forum.xwiki.org/user_avatar/forum.xwiki.org/hamsternl/32/19_2.png) [@HamsterNL](https://forum.xwiki.org/u/HamsterNL)\
**Post date:** [October 29, 2018, 12:11pm UTC](https://forum.xwiki.org/t/html-macro-create-a-link/3826/9 "2018-10-29T12:11:46Z")

</div>

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 😃

---

<div class="post-metadata">

**Author:** ![vmassol](https://forum.xwiki.org/user_avatar/forum.xwiki.org/vmassol/32/6_2.png) [@vmassol](https://forum.xwiki.org/u/vmassol)\
**Post date:** [October 29, 2018, 12:16pm UTC](https://forum.xwiki.org/t/html-macro-create-a-link/3826/10 "2018-10-29T12:16:21Z")

</div>

> [@HamsterNL](#):
>
> Guess I should have mentioned that we are still at XWiki 5.4.3 😫

I feel your pain! 🙂 Note that we don’t support old versions of XWiki: [https://www.xwiki.org/xwiki/bin/view/Main/Support#HSupportedVersions](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.
