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
You can do it with the help of the question you linked by following way
{{ asset(path('route',{'param1':'value'})) }}
If you need to handle multiple CDN domains you can do it by following way
In app/config.yml
# app/config.yml
#....
templating:
engines: ['twig']
packages:
cdn1:
base_urls: ["http://cdn1.domain.com"]
cdn2:
base_urls: ["http://cdn2.domain.com"]
And then in your twig template file
{{ asset('path/of/file', 'cdn1')
OR
{{ asset('path/of/file', 'cdn2')