1

I want to change the product reviews tab contents. I could do that with XML files:

<reference name="product.info">
    <action method="unsetChild">
        <name>product.reviews</name>
    </action>
    <block type="reviewcontainer/tabs" name="product.reviews" as="reviews" after="additional">
        <action method="addToParentGroup">
            <group>detailed_info</group>
        </action>
        <action method="setTitle" translate="value">
            <value>My Reviews</value>
        </action>
        <action method="setTemplate">
            <template>mymodule/review_tab.phtml</template>
        </action>
    </block>
</reference>

However I have some settings in the System/Configuration page that should control if the reviews are changed. So my question is how can I do this from code?

  • check if condition in layout file here – Minesh Patel Dec 2 '15 at 12:11
  • Hi, thanks for Your answer, however I need some more help :-\ So I need to have a widget, that replaces the reviews tab and it decides if the original tab data and title renders or my own? Thanks! – TeeCee Dec 10 '15 at 10:53
1

The action tag can have an attribute ifconfig like this:

<action ifconfig="your/config/path" method="unsetChild">

Adding blocks with <block> conditionally is not possible out-of-the box but here's a workaround:

Create the block outside of the layout hierarchy (only specify the block name here):

<catalog_product_view>

    ...

    <block type="reviewcontainer/tabs" name="product.reviews" />

</catalog_product_view>

and then add it conditionally using the insert action (specify position and alias here):

<catalog_product_view>

    ...

    <reference name="product.info">
        <action ifconfig="your/config/path" method="insert">
            <name>product.reviews</name>
            <sibling>additional</sibling>
            <after>true</after>
            <as>reviews</name>
        </action>
    </reference>
    <reference name="product.reviews">
        <action ifconfig="your/config/path" method="addToParentGroup">
            <group>detailed_info</group>
        </action>
        <action ifconfig="your/config/path" method="setTitle" translate="value">
            <value>My Reviews</value>
        </action>
        <action ifconfig="your/config/path" method="setTemplate">
            <template>mymodule/review_tab.phtml</template>
        </action>
    </reference>

</catalog_product_view>

I also moved all actions on the reviews block to a reference, and made them conditional with ifconfig. You don't need to do that but it's making the separation of block definition and block usage more clear IMHO.

  • Thanks, I read about the ifconfig, but all the first search results were mentioned with some modules and because of those I thought that it is provided by a module. – TeeCee Jan 4 '16 at 11:55

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.