Markus Michalski FAQ

Sylius Media Alt Text: Storefront

Storefront output of the Sylius Media Alt Text plugin: which templates print the alt text, decorative images in links, and the Twig function mmd_image_alt plus a partial for your own themes.

Deutsche Version

Back to overview

Sylius Media Alt Text: Storefront

This documentation always describes the latest published version.

Where the text appears

The plugin replaces five templates through Twig's bundle path override (templates/overrides/SyliusShopBundle and SyliusAdminBundle):

Template Effect
product/show/.../images/main_image.html.twig Main image of the product page
product/show/.../images/thumbnails/thumbnail.html.twig Thumbnails of the product gallery
product/index/.../header/image.html.twig Header image of the category
shared/components/main_image.html.twig Anonymous component sylius_shop:main_image, so product cards and cart
product/form/sections/media/images.html.twig (Admin) Image list in the product form, hosts the editor

Without maintained text the output stays as before. A decorative image outputs alt="".

If your shop has overridden one of these templates itself under templates/bundles/SyliusShopBundle, your template wins. Output the text there with mmd_image_alt (see below).

The product gallery wraps its images in links. A decorative image would leave the link without an accessible name, so in that case the link gets an aria-label with the product name.

Outputting the text in your own template

Twig function

mmd_image_alt

<img src="{{ image.path|imagine_filter('sylius_shop_product_thumbnail') }}" alt="{{ mmd_image_alt(image, product.name) }}">

Signature: mmd_image_alt(image, fallback = null, locale = null).

Partial for themes

A theme that must also render without the plugin must not call mmd_image_alt directly: an unknown Twig function fails already at compile time. Instead, include the partial together with a substitute template:

alt="{% include ['@MmdSyliusMediaAltTextPlugin/shop/image_alt.html.twig', 'my_fallback.html.twig'] with { image: image, fallback: product.name } only %}"

my_fallback.html.twig contains only {{ fallback }}. If the plugin is present, the partial outputs the text; otherwise the substitute template is used.

Additional Twig function

Function Description
mmd_media_alt_text_plugin_version() Installed plugin version (dev if it cannot be determined), used in the title of the settings page