Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/manuelodelain/linkify-twig-extension

Linkify Twig extension - Converts URLs and email addresses into HTML links
https://github.com/manuelodelain/linkify-twig-extension

Last synced: 21 days ago
JSON representation

Linkify Twig extension - Converts URLs and email addresses into HTML links

Lists

README

        

# Linkify Twig extension

Use [Linkify](https://github.com/misd-service-development/php-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 ... www.website.com ...
```

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 ... www.website.com ...
```

[See the Linkify options](https://github.com/misd-service-development/php-linkify#options)