Markus Michalski FAQ

Empty Category Messages: Extending

Twig function mmd_empty_category_message, the returned object, template blocks to override and notes for custom themes.

Deutsche Version

Back to overview

Extending

Twig function

The plugin provides the Twig function mmd_empty_category_message. It takes a category and returns a message object. For null the object is empty.

{% set emptyMessage = mmd_empty_category_message(page.category) %}

{% if emptyMessage.hasContent() %}
    {{ emptyMessage.message|sw_sanitize }}
{% endif %}

Inheritance and the image are only available for the category of the current category page (page.category), because only there does the plugin load the parent categories and the media. For other categories the function only returns message, CSS classes and alignments, but no image URL.

Returned object

Property Type Default Description
message string empty HTML message
imageUrl string empty Image URL
cssClass string empty Sanitized CSS classes
imageSize string medium small, medium or large
imageAlign string center left, center or right
textAlign string center left, center or right
Method Returns Description
--- --- ---
hasContent() bool Has a message or an image URL
hasMessage() bool Has a message
hasImage() bool Has an image URL
getImageMaxWidth() string 150px, 250px or 400px depending on image size
getImageJustify() string flex-start, center or flex-end depending on image alignment
getTextAlignCss() string Value for the text alignment, center if unset

The bundled template does not use getImageMaxWidth() and getImageJustify(). It works with the CSS classes.

Overriding the template

The plugin extends @Storefront/storefront/component/product/listing.html.twig and overrides the block element_product_listing_col_empty. In your own theme you can override these blocks of the plugin template:

Block Content
element_product_listing_col_empty_custom The entire custom message including fallback
element_product_listing_col_empty_custom_image Image area
element_product_listing_col_empty_custom_message Text area
element_product_listing_col_empty_alert Default message when no message is set

The plugin reads the custom field values from the category entity. The technical field names are listed under Configuration.