Extend the default routing extension class.
use Symfony\Bridge\Twig\Extension\RoutingExtension;
class MyRoutingExtension extends RoutingExtension
{
public function getPath($name, $parameters = array(), $relative = false)
{
}
}
Then specify your class using the parameter:
parameters:
twig.extension.routing.class: MyNamespace\MyRoutingExtension
==================================================== ======================
To add more dependencies, such as a domain in which you basically need to copy the service definition, and then add your stuff:
twig.extension.routing:
class: '%twig.extension.routing.class%'
public: false
arguments:
- '@router'
- 'domain'
class MyRoutingExtension extends RoutingExtension
{
protected $domain;
public function __construct($router,$domain)
{
parent::__construct($router);
$this->domain = $domain;
}
}
DependencyInjection. , . , , symfony . . .
, , , . .