Install the ContentProductWidget module

Edit on GitHub

The ContentProductWidget module renders Abstract Product List content items as product lists or sliders on the Storefront.

To integrate the ContentProductWidget module, follow these steps:

1) Install the module

Install the spryker-shop/content-product-widget module using Composer:

composer require spryker-shop/content-product-widget --update-with-dependencies
Verification

Make sure the following module is installed in vendor/spryker-shop:

MODULE EXPECTED DIRECTORY
ContentProductWidget vendor/spryker-shop/content-product-widget

2) Register the Twig plugin

Register the Twig plugin to make the content_product_abstract_list function available in Yves and CMS blocks.

src/Pyz/Yves/Twig/TwigDependencyProvider.php

<?php

namespace Pyz\Yves\Twig;

use Spryker\Yves\Twig\TwigDependencyProvider as SprykerTwigDependencyProvider;
use SprykerShop\Yves\ContentProductWidget\Plugin\Twig\ContentProductAbstractListTwigPlugin;

class TwigDependencyProvider extends SprykerTwigDependencyProvider
{
    /**
     * @return array<\Spryker\Shared\TwigExtension\Dependency\Plugin\TwigPluginInterface>
     */
    protected function getTwigPlugins(): array
    {
        return [
            ...
            new ContentProductAbstractListTwigPlugin(),
        ];
    }
}

3) Use the Twig function

After you register the plugin, you can render Abstract Product List content items by using the content_product_abstract_list function.

3.1 Function signature

FUNCTION DESCRIPTION
content_product_abstract_list(contentKey, templateIdentifier) Renders an Abstract Product List content item by its content key and the specified template.

Parameters:

  • contentKey (string): The unique key of the Abstract Product List content item (for example, the NAME used when creating the content item).
  • templateIdentifier (string): The identifier of the template to use. See Default templates.

Example (CMS block or CMS page template):

{{ content_product_abstract_list('best-sellers', 'bottom-title') }}
Verification
  1. In the Back Office, create an Abstract Product List content item.
  2. Add the content item to a CMS block or CMS page.
  3. Publish the block or page and open it on the Storefront.
  4. Check that the product list is rendered without errors.

4) Optional: Configure templates

By default, the ContentProductWidget module ships with two templates:

TEMPLATE IDENTIFIER PATH DESCRIPTION
bottom-title @ContentProductWidget/views/cms-product-abstract-list/cms-product-abstract-list.twig Product list with title at the bottom (slider for store or landing pages).
top-title @ContentProductWidget/views/cms-product-abstract-list-alternative/cms-product-abstract-list-alternative.twig Product list with title at the top.

To use a default template, pass its identifier as the second argument of the Twig function.

To add custom templates, extend the project-level Twig function provider for ContentProductWidget, and add your own identifiers and paths. For details, see Create CMS templates.

5) Optional: Extend product data with categories

You can extend the product data that ContentProductWidget uses with additional information, such as product categories. To do this, register collection expander plugins in the project-level ContentProductWidgetDependencyProvider.

The following example registers ProductCategoryContentProductAbstractCollectionExpanderPlugin, which enriches the abstract product collection with category data:

src/Pyz/Yves/ContentProductWidget/ContentProductWidgetDependencyProvider.php

<?php

namespace Pyz\Yves\ContentProductWidget;

use SprykerShop\Yves\ContentProductWidget\ContentProductWidgetDependencyProvider as SprykerContentProductWidgetDependencyProvider;
use SprykerShop\Yves\ProductCategoryWidget\Plugin\ContentProductWidget\ProductCategoryContentProductAbstractCollectionExpanderPlugin;

class ContentProductWidgetDependencyProvider extends SprykerContentProductWidgetDependencyProvider
{
    /**
     * @return array<\SprykerShop\Yves\ContentProductWidget\Dependency\Plugin\ContentProductAbstractCollectionExpanderPluginInterface>
     */
    protected function getContentProductAbstractCollectionExpanderPlugins(): array
    {
        return [
            new ProductCategoryContentProductAbstractCollectionExpanderPlugin(),
        ];
    }
}

This plugin extends the abstract product collection with category information so that you can display categories in your ContentProductWidget templates.

6) Next steps

After you install and integrate the ContentProductWidget module, you can: