1

I want to add Enable/disable functionality for a referenceBlock. <referenceBlock name="product_recommendations_pdp" remove="false" /> The referenceBlock can be remove="true" or remove="false" directly form admin-panel for just selecting.enter image description here

referenceBlock is located at app/design/frontend/ProjectName/store/Magento_ProductRecommendationsLayout/layout/catalog_product_view.xml

2
  • based on system.xml value??
    – Waqar Ali
    Commented Aug 25, 2020 at 13:01
  • Yes based on system.xml value. Commented Aug 25, 2020 at 13:05

2 Answers 2

1

Use ifconfig attribute

ifconfig will not work with <referenceBlock> tag. So you need to call the block again in your custom layout file and add ifconfig attribute with your config path. The blocks with same name gets eventually merged as one.

<block class="your_block_class" name="your_block_name" ifconfig="section_name/group_name/field_name" template="your_template_path" />
0

You can try a different approach to solve your issue.
I assume that you are using <referenceBlock name="product_recommendations_pdp" to add a block or execute an action on the specified block.
You can add the ifconfig attribute on your block or action tags.

<referenceBlock name="product_recommendations_pdp">
    <action method="setTemplate" ifconfig="section_name/group_name/field_name">
        <argument name="setTemplate" xsi:type="string"> your_template_path</argument>
    </action>
    <!-- or -->
    <block class="your_block_class_name" ifconfig="section_name/group_name/field_name">...</block>
</referenceBlock>

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.