Sonata Media Bundle : acces media url

前端 未结 5 2023
小蘑菇
小蘑菇 2021-01-02 01:09

I am using sonata media bundle.

and I was wondering how can I access the media url in twig.
I just want the url, I do not need to show the media.

Any sug

5条回答
  •  鱼传尺愫
    2021-01-02 01:57

    @javigzz's is perfect in case of default context. I used custom context, so had to handle $format first taking into account context name:

    $provider = $this->container->get($media->getProviderName());
    $format = $provider->getFormatName($media, $format);
    $url = $provider->generatePublicUrl($media, $format);
    

提交回复
热议问题