misd/linkify-bundle

Converts URLs and email addresses in text into HTML links

Installs: 10 522

Dependents: 0

Stars: 1

Watchers: 4

Open Issues: 1

Language: PHP

v1.0.4 2013-04-02 12:55 UTC

README

Build Status

Adds Linkify to your Symfony2 application, which converts URLs and email addresses in HTML (or plain text) to HTML links.

Authors

Installation

  1. Add LinkifyBundle to your dependencies:

    // composer.json
    
    {
        // ...
        "require": {
            // ...
            "misd/linkify-bundle": "~1.0"
        }
    }
    
  2. Use Composer to download and install LinkifyBundle:

    $ php composer.phar update misd/linkify-bundle
    
  3. Register the bundle in your application:

    // app/AppKernel.php
    
    class AppKernel extends Kernel
    {
        // ...
        public function registerBundles()
        {
            $bundles = array(
                // ...
                new Misd\LinkifyBundle\MisdLinkifyBundle(),
                // ...
            );
        }
        // ...
    }
    

Usage

Use the service:

$text = $this->container->get('misd.linkify')->process('This is my text containing a link to www.example.com.');

In a Twig template:

{{ "This is my text containing a link to www.example.com."|linkify }}

In a PHP template:

<?php echo $view['linkify']->process('This is my text containing a link to www.example.com.') ?>

Options

Requires Linkify v1.1.1 or newer.

An array of options can be passed (see the Linkify docs for futher details). So to add the link class to created links:

Using the service:

$text = $this->container->get('misd.linkify')->process('This is my text containing a link to www.example.com.', array('attr' => array('class' => 'link')));

In a Twig template:

{{ "This is my text containing a link to www.example.com."|linkify({'attr': {'class': 'link'}}) }}

In a PHP template:

<?php echo $view['linkify']->process('This is my text containing a link to www.example.com.', array('attr' => array('class' => 'link'))) ?>