I want to show only two recently viewed products in products page.How to add it in layout file in block.I am adding like

    <block class="Magento\Cms\Block\Block" name="recently_viewed" cacheable="false">
                <argument name="block_id" xsi:type="string">recently_viewed</argument>
           <argument method="setLimit">
               <argument name="limit" xsi:type="number">2</argument>


buts its not working

3 Answers 3


The problem is that, I assume, you're adding the widget in a Static Block then adding this block in your layout so when you add the setLimit method you are technically adding the limit to this block instead of the widget which won't work as you expect.

Instead you should use the Recently Viewed Products widget class directly in your layout like this:

<block class="Magento\Reports\Block\Product\Widget\Viewed" name="recently_viewed" cacheable="false" template="Magento_Reports::widget/viewed/content/viewed_grid.phtml">
    <action method="setPageSize">
        <argument name="page_size" xsi:type="number">4</argument>

This way you will only change the product count for this specific widget. Notice that it's not setLimit but setPageSize instead.


I'm not sure if you are only looking for an XML solution? If not then this change can be made through the admin Stores > Config > Catalog > Catalog > Recently Viewed/Compared Products > Default Recently Viewed Products Count

enter image description here

  • I want to show it in product listing and product details page,If i given there it will affect to both.But iwant count in product details page only
    – User0434
    Commented Oct 3, 2016 at 11:54
  • I see, my answer does not help then. I'll leave it here in case it can help someone else.
    – Ben Crook
    Commented Oct 3, 2016 at 12:19

In Magento 2 : Via Widget we can add "Limit to recently viewed products" without adding new static block and adding some logic in this and calling in layout...

Below I added steps to add a new widget for Recently Viewed Products

Note : PDP = Product Detail Page (Product Page)

So as per asked question we have to set Recently Viewed Limit to 2 in PDP so

In Admin Panel we have Content -> Widgets

Add Widget For Recently view choose widget type Recently Viewed Products

  1. Type = Recently Viewed Products

  2. Design Theme = Assign you theme


  3. Widget Title = PDP Recently Viewed Product (title add as per you need or understanding for future reference)

  4. Assign to Store Views = Select as you need

  5. Sort Order = (Add as per you need) else leave empty, it will set to 0

Layout Updates - Add Layout Update

  1. Display on = All Product Types or select which Product Type You want to display this section (example: simple,config ...)
  2. Products = All | Specific Products - As per you need you can choose all product or some of products...
  3. Container = Main Content Area or as per your PDP structure you can choose.
  4. Template = As per your PDP structure you can choose or you can override template into your theme if need changes on structure.

Now change the tab to Widget Options

Number of Products to display = 2 or as you need update this and save

After save Clear Cache and see or open some PDP's, You will get Recently Viewed in PDP.

if any concern on this please let me know i will help you out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.