Twig extension for Linkify - converts URLs and email addresses into HTML links

2.0 2019-12-12 09:12 UTC

This package is not auto-updated.

Last update: 2020-03-19 10:49:32 UTC


Use Linkify in your twig template.


Using Composer: composer require manuelodelain/linkify-twig-extension


use manuelodelain\Twig\Extension\LinkifyExtension;
use Twig\Environment;

$twig = new Environment(...);

$twig->addExtension(new LinkifyExtension());
{{ 'Lorem ipsum ... ...'|linkify }}

Will output:

Lorem ipsum ... <a href=""></a> ...

Don't forget to apply the raw filter for an HTML output:

{{ 'Lorem ipsum ... ...'|linkify|raw }}


As Linkify, set default options at the instanciation or at the method call.

At the instanciation (applied to all links):

use manuelodelain\Twig\Extension\LinkifyExtension;

$twig = new Environment(...);

$twig->addExtension(new LinkifyExtension(array('attr' => array('target' => '_blank'))));

At the method call:

{{ 'Lorem ipsum ... ...'|linkify({"attr": {"target": "_blank"}}) }}

Will output:

Lorem ipsum ... <a href="" target="_blank"></a> ...

See the Linkify options