A Twig extension for abr4xas/twig-slug.
$ composer require abr4xas/twig-slug
$ composer dumpautoload -o // optional
or add this to your composer.json
"require": {
"abr4xas/twig-slug": "dev-master"
}
and
$ composer update
$ composer dumpautoload -o // optional
First register the extension with Twig:
$twig = new Twig_Environment($loader);
$twig->addExtension(new \SeoUrl\SeoUrl());
then use it in your templates:
{{ This is an awesome string | seourl }} // output: this-is-an-awesome-string
in SomeController
like this:
<?php
namespace SomeNameSpace;
use SeoUrl\SeoUrl;
class SomeController
{
public function someFunction()
{
$str = 'This is an awesome string';
$seoUrl = SeoUrl::generateSlug($str); // output: this-is-an-awesome-string
}
}