Skip to content

product_producer

The product_producer macro is used to render a producer of a given product in the text or image form.

Definition

{% product_producer(product, options) %}

Input parameters

product

Product parameter represents a Product object from ObjectApi.

options

object represents an object of product producer options

Option key Type Default Required Description
options.moveTo string - no If set to url and a producer website is set, the link will direct to the website. If the website is not set the link will direct to products from this producer in the store.
options.display string - no If set to logo a logo of the producer will be displayed. If no logo is set or the display parameter is set to name just necessary aria attributes allowing to conveniently read this element by the screen readers will be displayed
options.classNames string "" no Classes that will be appended to the main <div> element

Example

In this example we render a simple product producer. To get the product object we use the getProduct() method from ObjectApi.

{% from "@macros/product_producer.twig" import product_producer %}

{% set product = ObjectApi.getProduct(product_id) %}

{{ product_producer(product) }}

Example

In this example we render a product producer as a logo image.

{% from "@macros/product_producer.twig" import product_producer %}

{% set product = ObjectApi.getProduct(product_id) %}

{{ product_producer(product, { display: 'logo' }) }}

Example

In this example we render a product producer as a logo imag with a link to the producer's website.

{% from "@macros/product_producer.twig" import product_producer %}

{% set product = ObjectApi.getProduct(product_id) %}

{{ product_producer(product, { moveTo: 'url', display: 'logo' }) }}

Macro source code

{% macro product_producer(product, options) %}
    {% from "@macros/image.twig" import image %}

    <a class="link link_secondary product-producer__link {{ options.classNames }}"
        {% if options.moveTo == 'url' and product.producer.website %}
            href="{{ product.producer.website }}" target="_blank" rel="noopener nofollow"
        {% else %}
            href="{{ product.producer.url.relative }}"
        {% endif %}

        {% if options.display == 'name' or (options.display == 'logo' and not product.producer.imageUrl) %}
            aria-label="
                {% if options.moveTo == 'url' and product.producer.website %}
                    {{ translate('Manufacturer: %s (go to page: %s)', [product.producer.name, product.producer.website]) }}
                {% else %}
                    {{ translate('Manufacturer: %s (go to products)', product.producer.name) }} {% endif %}"
            title="
                {% if options.moveTo == 'url' and product.producer.website %}
                    {{ translate('Manufacturer: %s (go to page: %s)', [product.producer.name, product.producer.website]) }}
                {% else %}
                    {{ translate('Manufacturer: %s (go to products)', product.producer.name) }}
                     {% endif %}"
        {% endif %}
    >
        {% if options.display == 'logo' and product.producer.imageUrl %}
            {{
            image({
                img: {
                    src: product.producer.imageUrl.relative,
                    class: 'product-producer__image',
                    alt: options.moveTo == 'url' and product.producer.website ?
                    translate('Manufacturer: %s (go to page: %s)', [product.producer.name, product.producer.website]) :
                    translate('Manufacturer: %s (go to products)', product.producer.name),
                    title: options.moveTo == 'url' and product.producer.website ?
                    translate('Manufacturer: %s (go to page: %s)', [product.producer.name, product.producer.website]) :
                    translate('Manufacturer: %s (go to products)', product.producer.name)
                }
            }, [
                {
                    src: product.producer.imageUrl.relative,
                    type:  'image/jpeg'
                }
            ])
            }}
        {% else %}
            {{ product.producer.name }}
        {% endif %}
    </a>
{% endmacro %}

Macros reference

Used Object Api methods

Used styles