I created my custom Block (php class), I add this Block inside two different containers on different blocks in xml file, each block also has a different .phtml

My php block is customizable by arguments passed via xml.

If I disable the cache, my blocks works fine. While with the cache enabled, I get twice the first block.

Here my code:

In <vendor>/<module>/view/frontend/layout/cms_index_index.xml:

<?xml version="1.0"?><page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="content">
        <referenceContainer name="evidenza">
            <block class="<Vendor>\<Module>\Block\ProductsList" name="product-evidenza" template="<Vendor>_<Module>::grid.phtml">
                    <argument name="title_1" xsi:type="string">IN</argument>
                    <argument name="title_2" xsi:type="string">EVIDENZA</argument>
                    <argument name="title_span_class" xsi:type="string">red-satur-text</argument>
                    <argument name="products_count" xsi:type="string">4</argument>
                    <argument name="type_grid" xsi:type="string">evidenza</argument>
        <referenceContainer name="ispirazioni">
            <block class="<Vendor>\<Module>\Block\ProductsList" name="product-ispirazioni" template="<Vendor>_<Module>::ispirazioni.phtml">
                    <argument name="title_1" xsi:type="string">ISPIRAZIONI</argument>
                    <argument name="products_count" xsi:type="string">2</argument>
                    <argument name="type_grid" xsi:type="string">ispirazioni</argument>

My php Block is used only to get the collection of the products in different ways according to the xml arguments.


I think you should remove attribute cache="false" in the tag of the layout.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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