8. MediaBundle IntegrationΒΆ
There is an (optional) integration with the SonataMediaBundle
. This integration allows you to add image to Category and Collection objects.
If you have the SonataMediaBundle
in your dependencies, then a new input will be visible in the admin. In order to make them work properly, you need to configure the sonata_media
section like this:
- YAML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
sonata_media: # default configuration contexts: # ... other contexts ... sonata_collection: providers: - sonata.media.provider.image formats: preview: { width: 100, quality: 100} wide: { width: 820, quality: 100} sonata_category: providers: - sonata.media.provider.image formats: preview: { width: 100, quality: 100} wide: { width: 820, quality: 100}
So, you can display the image category like this:
1 2 3 4 5 6 7 | <h1>{{ category.name}}</h1>
{% if category.media %}
<div class="media">
{% media category.media, 'wide' %}
</div>
{% endif %}
|