1

I want to create a module that changes the title and content of review tab in product page. So far I succeeded to do it using the layout in /app/design/frontend/base/default/layout/me/reviewcontainer.xml:

<?xml version="1.0" encoding="UTF-8"?>
<layout version="1.0.0">
    <!-- Product view -->
    <catalog_product_view>
        <reference name="product.reviews">
            <action method="setTemplate">
                <template>my/reviewcontainer/tabs.phtml</template>
            </action>
        </reference>
        <reference name="product.info">
            <action method="unsetChild">
                <name>product.reviews</name>
            </action>
            <block type="reviewcontainer/tabs" name="product.reviews" as="reviews"
                   template="my/reviewcontainer/tabs.phtml" after="additional">
                <action method="addToParentGroup">
                    <group>detailed_info</group>
                </action>
                <action method="setTitle" translate="value">
                    <value>Reviews (xxx)</value>
                </action>
            </block>
        </reference>
    </catalog_product_view>
</layout>

My etc/config.xml looks like this:

<?xml version="1.0"?>
<config>
    <modules>
        <my_ReviewContainer>
            <version>1.0.0</version>
        </my_ReviewContainer>
    </modules>    
    <!-- we are making changes to the frontend -->
    <frontend>    
        <!-- we are making changes to the layout -->
        <layout>    
            <!-- we are adding a new update file -->
            <updates>    
                <!--
                    this child node name must be
                    unique throughout Magento
                -->
                <my_ReviewContainer>    
                    <!-- the name of the layout file we are adding -->
                    <file>my/reviewcontainer.xml</file>
                </my_ReviewContainer>
            </updates>
        </layout>
    </frontend>
</config>

The template is in /app/design/frontend/base/default/template/my/reviewcontainer/tabs.phtml and has basic HTML.

Is it possible to change the Reviews (xxx) to be dynamically generated by a controller/model/block? If so, what files should I create and where should i put them (being newbie in Magento).

Second, is it possible for me to call some functions in this new controller from withing the tab template? (instead of writing HTML there).

1
  • I have answer for your 1st question. But 'm not clear about your requirement in second question. Commented Jul 17, 2015 at 2:27

1 Answer 1

0

You need to do two things.

Step 1 :

Define <helpers> in your config.xml.

<config>
   ...
    <global>
       <helpers>
           <yourhelper>
             <class>Namespace_Module_Helper</class>
           </yourhelper>
       </helpers>
    </global>
   ...
</config>

Then create new file helper in app/code/{local|community}/Namespace/Yourmodule/Helper/Data.php

<?php

class Namespace_Your module_Helper_Data extends Mage_Core_Helper_Abstract {
     public function yourfunction(){
       //your logic
      }
}

Step 2:

Change your layout file as

<action method="setTitle" translate="value">
      <value helper="yourhelper/data/yourfunction"/>
</action>

So in this the value will get from your helper. In this way you can use your php login the layout file.

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.