<p>The template engine (<a href="http://twig.sensiolabs.org/" rel="nofollow">Twig</a>) doesn't do anything like that – my guess is that the links only <em>appear</em> to render like your second example, because you're looking at the markup in your browser's dev tools, and modern browsers (e.g. Chrome) do a pretty good job of rendering invalid HTML.</p>

<p>Take a look at the raw source code (i.e. "View source" in your browser), and I suspect the actual rendered HTML will look exactly like your first example.</p>

<p>In any case, nesting <code>&lt;a&gt;</code> tags is not allowed and a very bad idea – so I'd recommend not doing it all :)</p>

CC BY-SA 3.0
2016-08-26T16:14:15.177Z
If you ignore the phrase "template engine" , I think what he's asking is not about Twig but actually Redactor.    If you paste the snippet mentioned into source code mode, Redactor will do exactly as he mentions. I can see how some users might think that's part of the the "template engine."
RitterKnight
CC BY-SA 3.0
2016-08-26T16:45:42.913Z
@RitterKnight You might be right, and you should add an additional answer - if the OP is talking about Redactor, it might be that turning off the "Purify HTML?" option for the Rich Text field will do the trick. Still a bad idea, though :)
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2016-08-26T10:45:16.063Z
2016-08-26T15:40:36.543Z
2016-08-26T15:40:36.543Z
Mats Mikkel Rummelhoff
<p>Redactor is, very sensibly, correcting your invalid html. <strong>You can't have links inside links</strong>, the spec does not allow it: <a href="https://www.w3.org/TR/html5/text-level-semantics.html#the-a-element">https://www.w3.org/TR/html5/text-level-semantics.html#the-a-element</a></p>

<p>Even if Redactor didn't do this, the browser will treat your invalid html as invalid and take a best guess at reconstructing it to form valid html; probably with varying results.</p>

CC BY-SA 3.0
2016-08-30T10:44:56.253Z
2016-08-30T10:44:56.253Z
Seth Warburton
<p>I have a little issue with Redactor. Whenever I have a link within a link: </p>

<pre><code>&lt;a href="#"&gt;main link &lt;a href="#"&gt;link within link&lt;/a&gt; &lt;/a&gt;
</code></pre>

<p>Redactor automatically modifies it to this:</p>

<pre><code>&lt;a href="#"&gt;main link&lt;/a&gt; &lt;a href="#"&gt;link within link&lt;/a&gt;
</code></pre>

<p>Is there a way to stop this auto-modification?</p>

CC BY-SA 3.0
2016-08-26T16:15:26.780Z
Redactor, Craft's rich text editor, actually does this, not the "template engine" (Twig). Is that what you mean?
RitterKnight
CC BY-SA 3.0
2016-08-26T16:48:10.317Z
As this is a Twig related question (or possibly, Redactor, as per @RitterKnight's comment) I think this question is absolutely relevant and shouldn't be closed.
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2016-08-27T22:10:38.623Z
@MatsMikkelRummelhoff: Agreed, great catch. Voting to "leave open", and I'll edit the question to better reflect Redactor's role.
Lindsey D
<redactor>
Redactor splitting nested <a> tags
# Redactor splitting nested <a> tags

(Asked by: username_0 on 2016-08-26)

I have a little issue with Redactor. Whenever I have a link within a link: 
main link link within link 

Redactor automatically modifies it to this:
main link link within link

Is there a way to stop this auto-modification?

**Tags:** redactor

> **Comments:**
> **username_1**: Redactor, Craft's rich text editor, actually does this, not the "template engine" (Twig). Is that what you mean?  
> **username_2**: As this is a Twig related question (or possibly, Redactor, as per @username_1's comment) I think this question is absolutely relevant and shouldn't be closed.  
> **username_3**: @MatsMikkelRummelhoff: Agreed, great catch. Voting to "leave open", and I'll edit the question to better reflect Redactor's role.  

---

## 2 answers

### Answer by username_2 on 2016-08-26. Score: 6

The template engine ([Twig](http://twig.sensiolabs.org/)) doesn't do anything like that – my guess is that the links only *appear* to render like your second example, because you're looking at the markup in your browser's dev tools, and modern browsers (e.g. Chrome) do a pretty good job of rendering invalid HTML.

Take a look at the raw source code (i.e. "View source" in your browser), and I suspect the actual rendered HTML will look exactly like your first example.

In any case, nesting  tags is not allowed and a very bad idea – so I'd recommend not doing it all :)

> **Comments:**
> **username_1**: If you ignore the phrase "template engine" , I think what he's asking is not about Twig but actually Redactor.    If you paste the snippet mentioned into source code mode, Redactor will do exactly as he mentions. I can see how some users might think that's part of the the "template engine."  
> **username_2**: @username_1 You might be right, and you should add an additional answer - if the OP is talking about Redactor, it might be that turning off the "Purify HTML?" option for the Rich Text field will do the trick. Still a bad idea, though :)  

---

### Answer by username_4 on 2016-08-30. Score: 5

Redactor is, very sensibly, correcting your invalid html. **You can't have links inside links**, the spec does not allow it: <https://www.w3.org/TR/html5/text-level-semantics.html#the-a-element>

Even if Redactor didn't do this, the browser will treat your invalid html as invalid and take a best guess at reconstructing it to form valid html; probably with varying results.


---

