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

<a href="#">main link <a href="#">link within link</a> </a>

Redactor automatically modifies it to this:

<a href="#">main link</a> <a href="#">link within link</a>

Is there a way to stop this auto-modification?

  • 2
    Redactor, Craft's rich text editor, actually does this, not the "template engine" (Twig). Is that what you mean? Commented Aug 26, 2016 at 16:15
  • 1
    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. Commented Aug 26, 2016 at 16:48
  • @MatsMikkelRummelhoff: Agreed, great catch. Voting to "leave open", and I'll edit the question to better reflect Redactor's role.
    – Lindsey D
    Commented Aug 27, 2016 at 22:10

2 Answers 2


The template engine (Twig) 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 <a> tags is not allowed and a very bad idea – so I'd recommend not doing it all :)

  • 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." Commented Aug 26, 2016 at 16:14
  • @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 :) Commented Aug 26, 2016 at 16:45

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.