aendra
aendra

Reputation: 5346

Get list of all JavaScript files being included on the Magento front end?

I'm trying to write some code that bridges Magento with Drupal and I want a simple way of adding Magento's frontend JavaScript to pages served by Drupal.

To this end: how do I return an array of URLs to JavaScript files used by Magento on the frontend? Specifically, I'm looking for the default layout handle and the individual product page.

Thanks!

Upvotes: 0

Views: 971

Answers (1)

benmarks
benmarks

Reputation: 23205

This will get you pretty close:

$update = Mage::app()->getLayout()->getUpdate();
$update->load(array('default','catalog_product_view'));
$xml = $update->asSimplexml();
$js = $xml->xpath('//action[@method="addJs"]');
Zend_Debug::dump($js);

The xpath argument could be refined to //action[@method="addJs"]/script for core code.

Of course, there are other arguments which add JS files (e.g. addItem) which will require additional handling.

Upvotes: 3

Related Questions