This stackoverflow solution almost answers my question. But I want to generate CDN urls in Twig to more than just resources. I\'d like to generate them for dynamic
I don't know about the CDN stuff but as far as extending the url function, take a look at:
Symfony\Bridge\Twig\Extension\RoutingExtension
public function __construct(UrlGeneratorInterface $generator)
{
$this->generator = $generator;
}
public function getFunctions()
{
return array(
'url' => new \Twig_Function_Method($this, 'getUrl'),
'path' => new \Twig_Function_Method($this, 'getPath'),
);
}
public function getPath($name, $parameters = array())
{
return $this->generator->generate($name, $parameters, false);
}
public function getUrl($name, $parameters = array())
{
return $this->generator->generate($name, $parameters, true);
}
So you could get at getUrl there or you could insert you own UrlGenerator. Not sure which would be easier in your specific case. Probably making your own UrlGenerator.