The text2html filter converts a plain-text string to HTML characters. Newline characters are converted to <br> tags.

URLs are also converted to links.

{{ post.plainDescription|text2html }}

You can specify the link target and whether or not to strip out the domain from the URL if the link is for a page within the same website.

{{ post.plainDescription|text2html('_blank', true) }}


The text2html filter has the following signature.

text2html(linkTarget, removeDomain)

Argument Description

This would set the value for the "target" attribute on the link tag. All generated links would have this value. For example, to have links open in a new tab/window you could do the following:

{{ post.plainDescription|text2html('_blank') }}


The removeDomain parameter is a boolean value that sets whether or not the domain for the URL should be removed if the link is within the same site.

This defaults to false, which means that the domain will not be removed.

For example, if your website is https://www.mydomain.com and the link is for https://www.mydomain.com/here/is/my/page then you could have the "https://www.mydomain.com" text removed from the link. Just pass true as the second parameter.

{{ post.plainDescription|text2html('_blank', true) }}

If you don't want to set a link target then you can use null as the first parameter value.

{{ post.plainDescription|text2html(null, true) }}

< Back to the list of filters