Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

Hi some one explain about

<file> tag in layout file.

I have use one third party extension. In their layout file they have use the below code.

<action method="addJs">
     <file helper="rewardssocial/purchase_share/getJs" />
     <script>tbt/rewardssocial/purchase/share/reward.js</script>
</action>

I don't know what the purpose of the file tag in that.

Cheers.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Lets start from <action method="addJs">.

This is the same as calling

Mage_Page_Block_Html_Head::addJs()

But if you take a look at methods signature, you will see that it has two parameters.

public function addJs($name, $params = "")

That means that content of tags

 <file helper="rewardssocial/purchase_share/getJs" />
 <script>tbt/rewardssocial/purchase/share/reward.js</script>

will be passed as $name and $params values. Name of tags here means nothing.

Order is only important.

<file> tag has no content. But has helper attribute, which tells that the result of helper method execution will be passed as first attribute value.

So as a result this xml is equal to.

Mage_Page_Block_Html_Head::addJs(
    Mage::helper('rewardssocial/purchase_share')->getJs(),
    'tbt/rewardssocial/purchase/share/reward.js'
);

Also you can specify parameters which can be passed to your helper

<file helper="rewardssocial/purchase_share/getJs">
    <arg>Now with arg!</arg>
    <!-- more args here -->
</file>

This is equal to

Mage::helper('rewardssocial/purchase_share')->getJs('Now with arg!')
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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