Skip to content

Custom recommendation rendering

You can use existing controllers to render recommendations outside the Page Builder. The controllers responsible for rendering block recommendations on the front-end are independent and can be used to render recommendations for specific strategies.

Each controller can be used to retrieve and display recommendations within a Twig template as follows:

1
2
3
4
5
{{ render(controller('<Controller name>', {
    'limit': limit,
    'template': '@ibexadesign/<your_template_path>.html.twig',
    '<another_parameter>': parameter_value
})) }}

The controllers are placed in the Ibexa\Bundle\ConnectorRaptor\Controller\Block namespace.

Each controller always requires these two parameters:

  • limit – the number of recommendations to render
  • template – the path to the template

Any other required parameters are specific to each controller and are detailed in the Parameters column of the table below:

Block name Controller Parameters Recommendation item type
Content that have been seen along with the item category ContentBasedOnProductCategoryBlockController
::showAction()
categoryId (integer),
limit (integer),
template (string)
Content
Most popular content PopularContentBlockController
::showAction()
limit (integer),
template (string)
Content
Most popular products PopularItemsBlockController
::showAction()
showInStock (boolean),
limit (integer),
template (string)
Product
Most popular products in category PopularItemsInCategoryBlockController
::showAction()
categoryId (integer),
showInStock (boolean),
limit (integer),
template (string)
Product
Other customers have also seen SimilarItemsBlockController
::showAction()
productCode (string),
showInStock (boolean),
limit (integer),
template (string)
Product
Other customers have also seen this content SimilarContentBlockController
::showAction()
contentId (integer),
limit (integer),
template (string)
Content
Other Customers Have also Purchased block OtherCustomersAlsoPurchasedBlockController
::showAction()
productCode (string),
limit (integer),
template (string)
Product
Personalized content recommendations UserContentRecommendationsBlockController
::showAction()
limit (integer),
template (string)
Content
The Personal Shopping Assistant UserItemRecommendationsBlockController
::showAction()
productCode (string),
showInStock (boolean),
limit (integer),
template (string)
Product
User's item history UserItemHistoryBlockController
::showAction()
showInStock (boolean),
limit (integer),
template (string)
Product

Each template receives a recommendations Twig variable, which is a list containing either Ibexa\Contracts\ProductCatalog\Values\ProductInterface instances for product recommendations or Ibexa\Contracts\Core\Repository\Values\Content\Content instances for content recommendations.

Two generic templates are provided and can be used in ./templates/themes/<theme> directory:

  • @ibexadesign/ibexa/recommendations/_content_list.html.twig for content items:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{% if recommendations is not empty %}
    {% for content in recommendations %}
        {% set location = content.contentInfo.mainLocation %}
        {% if location %}
            <p><a href="{{ ibexa_path(location) }}">{{ ibexa_content_name(content) }}</a></p>
        {% else %}
            <p>{{ ibexa_content_name(content) }}</p>
        {% endif %}
    {% endfor %}
{% endif %}
  • @ibexadesign/ibexa/recommendations/_product_list.html.twig for products:
1
2
3
4
5
6
7
{% if recommendations is not empty %}
    <ul>
        {% for product in recommendations %}
            <li><a href="{{ ibexa_path(product) }}">{{ product.name }}</a></li>
        {% endfor %}
    </ul>
{% endif %}

To fetch recommendations for the remaining modules, you need to create a custom controller and use a method from Ibexa\Contracts\ConnectorRaptor\Recommendations\RecommendationsServiceInterface.

Using this method, recommendations can be displayed on any page, for example on a specific product page, as shown below:

Custom rendering