manuelodelain/linkify-twig-extension

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: 2024-04-12 05:28:20 UTC


README

Use Linkify in your twig template.

Installation

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

Usage

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

$twig = new Environment(...);

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

Will output:

Lorem ipsum ... <a href="www.website.com">www.website.com</a> ...

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

{{ 'Lorem ipsum ... www.website.com ...'|linkify|raw }}

Options

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 ... www.website.com ...'|linkify({"attr": {"target": "_blank"}}) }}

Will output:

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

See the Linkify options