0

I am not able to add a cms block in category page.

XML: <block class="Magento\Framework\View\Element\Template" name="catalog.filter.content.bottom" template="my_module::test.phtml"/>

what I have tried:

<referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template" name="catalog.filter.content.bottom" template="Amasty_Shopby::layer/test.phtml"/>
        <block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml">
            <block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">
                <container name="category.product.list.additional" as="additional" />
                <block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
                    <block class="Magento\Framework\View\Element\Template" name="category.product.type.details.renderers.default" as="default"/>
                </block>
                <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="category.product.addto" as="addto">
                    <block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
                           name="category.product.addto.compare" as="compare"
                           template="Magento_Catalog::product/list/addto/compare.phtml"/>
                </block>
                <!-- addedJust before product_list_toolbar does not work!?--><block class="Magento\Framework\View\Element\Template" name="catalog.filter.content.bottom" template="My_Module::test.phtml"/> 
                <block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
                    <block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
                </block>
                <action method="setToolbarBlockName">
                    <argument name="name" xsi:type="string">product_list_toolbar</argument>
                </action>
            </block>
        </block>
      ......

Next tried to add to product_list_toolbar:

<referenceContainer name="product_list_toolbar">
        <block class="Magento\Framework\View\Element\Template" name="catalog.filter.content.bottom" template="My_Module::test.phtml"/>
    </referenceContainer>

Yet without luck.

If add within content it works but it will be added either before the list at the very top or a the bottom after the tool bar which is not what I need.

What I need can be see in the screen shoot bellow!

enter image description here

Anyone have any idea? Thanks.

0

You can call your static block/PHTML file in list.phtml file which is located at Magento_Catalog\templates\product folder.

Find <?= $block->getToolbarHtml() ?> code at below in list.phtml line no 119 in default file and add code above this line like below:

For static block

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>

Note: Replace static block_identifier with your static block identifier.

For PHTML file

<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("my_module::test.phtml")->toHtml();?>
  • I thought of that already but that's not ideal I can't overwrite this file in my custom module as it's also being overwritten in the custom theme. – Juliano Vargas Nov 15 '18 at 9:12

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.